mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Merge pull request #389 from jasonrudolph/always_flush_logger_at_exit
Always flush logger at exit
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user