Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always flush logger at exit #389

Merged
merged 2 commits into from
May 6, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions railties/lib/rails/application/bootstrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 8 additions & 14 deletions railties/lib/rails/commands/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions railties/test/application/rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down