Merge pull request #389 from jasonrudolph/always_flush_logger_at_exit

Always flush logger at exit
This commit is contained in:
José Valim
2011-05-06 09:43:57 -07:00
3 changed files with 22 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ module Rails
)
logger
end
at_exit { Rails.logger.flush if Rails.logger.respond_to?(:flush) }
end
# Initialize cache early in the stack so railties can make use of it.

View File

@@ -39,18 +39,12 @@ ENV["RAILS_ENV"] = options[:environment]
require APP_PATH
Rails.application.require_environment!
begin
if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
exit 1
elsif File.exist?(code_or_file)
$0 = code_or_file
eval(File.read(code_or_file), nil, code_or_file)
else
eval(code_or_file)
end
ensure
if defined? Rails
Rails.logger.flush if Rails.logger.respond_to?(:flush)
end
if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
exit 1
elsif File.exist?(code_or_file)
$0 = code_or_file
eval(File.read(code_or_file), nil, code_or_file)
else
eval(code_or_file)
end

View File

@@ -73,6 +73,19 @@ module ApplicationTests
assert_match 'custom_assets GET /custom/assets(.:format)', Dir.chdir(app_path){ `rake routes` }
end
def test_logger_is_flushed_when_exiting_production_rake_tasks
add_to_config <<-RUBY
rake_tasks do
task :log_something => :environment do
Rails.logger.error("Sample log message")
end
end
RUBY
output = Dir.chdir(app_path){ `rake log_something RAILS_ENV=production && cat log/production.log` }
assert_match "Sample log message", output
end
def test_model_and_migration_generator_with_change_syntax
Dir.chdir(app_path) do
`rails generate model user username:string password:string`