aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/buffered_logger.rb1
-rw-r--r--activesupport/test/buffered_logger_test.rb10
3 files changed, 13 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index 14029fb8f4..cd0106c0b5 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that BufferedLogger should create its own directory if one doesn't already exist #11285 [lotswholetime]
+
* Fix Numeric time tests broken by DST change by anchoring them to fixed times instead of Time.now. Anchor TimeZone#now DST test to time specified with Time.at instead of Time.local to work around platform differences with Time.local and DST representation [Geoff Buesing]
* Removing unneeded #change_time_zone method from Time, DateTime and TimeWithZone [Geoff Buesing]
diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb
index c46386c6b0..67b0a580ea 100644
--- a/activesupport/lib/active_support/buffered_logger.rb
+++ b/activesupport/lib/active_support/buffered_logger.rb
@@ -47,6 +47,7 @@ module ActiveSupport
@log = open(log, (File::WRONLY | File::APPEND))
@log.sync = true
else
+ FileUtils.mkdir_p(File.dirname(log))
@log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
@log.sync = true
@log.write("# Logfile created on %s" % [Time.now.to_s])
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb
index 9fdf078f5d..2e8118bdbc 100644
--- a/activesupport/test/buffered_logger_test.rb
+++ b/activesupport/test/buffered_logger_test.rb
@@ -104,4 +104,14 @@ class BufferedLoggerTest < Test::Unit::TestCase
@logger.info 'there it is.'
assert !@output.string.empty?, @output.string
end
+
+ def test_should_create_the_log_directory_if_it_doesnt_exist
+ tmp_directory = File.join(File.dirname(__FILE__), "tmp")
+ log_file = File.join(tmp_directory, "development.log")
+ assert !File.exist?(tmp_directory)
+ @logger = ActiveSupport::BufferedLogger.new(log_file)
+ assert File.exist?(tmp_directory)
+ ensure
+ FileUtils.rm_rf(tmp_directory)
+ end
end