Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #389 from jasonrudolph/always_flush_logger_at_exit

Always flush logger at exit
  • Loading branch information...
commit 6acb858d06fa0873135eea0957a4aa5ea2fd0d2b 2 parents cae68d2 + cb2d811
@josevalim josevalim authored
View
1  railties/lib/rails/application/bootstrap.rb
@@ -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.
View
22 railties/lib/rails/commands/runner.rb
@@ -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
View
13 railties/test/application/rake_test.rb
@@ -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`
Please sign in to comment.
Something went wrong with that request. Please try again.