diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/log_subscriber.rb | 13 | ||||
-rw-r--r-- | railties/lib/rails/rack/logger.rb | 7 |
2 files changed, 14 insertions, 6 deletions
diff --git a/railties/lib/rails/log_subscriber.rb b/railties/lib/rails/log_subscriber.rb index 145c7e0ace..9a74fee745 100644 --- a/railties/lib/rails/log_subscriber.rb +++ b/railties/lib/rails/log_subscriber.rb @@ -52,6 +52,7 @@ module Rails def self.add(namespace, log_subscriber, notifier = ActiveSupport::Notifications) log_subscribers << log_subscriber + @flushable_loggers = nil log_subscriber.public_methods(false).each do |event| notifier.subscribe("#{event}.#{namespace}") do |*args| @@ -70,11 +71,17 @@ module Rails @log_subscribers ||= [] end + def self.flushable_loggers + @flushable_loggers ||= begin + loggers = log_subscribers.map(&:logger) + loggers.uniq! + loggers.select { |l| l.respond_to?(:flush) } + end + end + # Flush all log_subscribers' logger. def self.flush_all! - loggers = log_subscribers.map(&:logger) - loggers.uniq! - loggers.each { |l| l.flush if l.respond_to?(:flush) } + flushable_loggers.each(&:flush) end # By default, we use the Rails.logger for logging. diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index dd8b342f59..73e9af3b41 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -1,4 +1,5 @@ require 'rails/log_subscriber' +require 'active_support/core_ext/time/conversions' module Rails module Rack @@ -19,10 +20,10 @@ module Rails def before_dispatch(env) request = ActionDispatch::Request.new(env) - path = request.fullpath.inspect rescue "unknown" + path = request.fullpath - info "\n\nStarted #{request.method.to_s.upcase} #{path} " << - "for #{request.remote_ip} at #{Time.now.to_s(:db)}" + info "\n\nStarted #{env["REQUEST_METHOD"]} \"#{path}\" " \ + "for #{request.ip} at #{Time.now.to_default_s}" end def after_dispatch(env) |