提交 6acb858d 编写于 作者: J José Valim

Merge pull request #389 from jasonrudolph/always_flush_logger_at_exit

Always flush logger at exit
......@@ -37,6 +37,7 @@ module Bootstrap
)
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.
......
......@@ -39,18 +39,12 @@
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
......@@ -73,6 +73,19 @@ def test_rake_routes_shows_custom_assets
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`
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册