From 13ab55f7371a2d2f0311be97bb5ed6c8378725f7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 13 Mar 2008 01:54:34 +0000 Subject: Fixed that BufferedLogger should create its own directory if one doesnt already exist (closes #11285) [lotswholetime] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9013 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/buffered_logger.rb | 1 + activesupport/test/buffered_logger_test.rb | 10 ++++++++++ 3 files changed, 13 insertions(+) (limited to 'activesupport') 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 -- cgit v1.2.3