From b0994be5bd24559f1362a636b46271de6d6a92d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 15 Jan 2010 10:46:30 +0100 Subject: LogTailer should be invoked after all logs in threads were flushed. --- railties/lib/rails/subscriber.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'railties/lib/rails/subscriber.rb') diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/subscriber.rb index 88a6f77eaa..2c62f178b8 100644 --- a/railties/lib/rails/subscriber.rb +++ b/railties/lib/rails/subscriber.rb @@ -33,8 +33,9 @@ module Rails # Subscriber also has some helpers to deal with logging and automatically flushes # all logs when the request finishes (via action_dispatch.callback notification). class Subscriber - cattr_accessor :colorize_logging, :instance_writer => false + mattr_accessor :colorize_logging, :tail_log self.colorize_logging = true + self.tail_log = false # Embed in a String to clear all previous ANSI sequences. CLEAR = "\e[0m" @@ -58,6 +59,12 @@ module Rails @subscribers ||= {} end + # Use Rails::Rack::LogTailer to do the log tailing. + # TODO Leave this as middleware or move inside Subscriber? + def self.log_tailer + @log_tailer ||= Rails::Rack::LogTailer.new(nil, "log/#{Rails.env}.log") + end + def self.dispatch(args) namespace, name = args[0].split(".") subscriber = subscribers[namespace.to_sym] @@ -66,7 +73,10 @@ module Rails subscriber.send(name, ActiveSupport::Notifications::Event.new(*args)) end - flush_all! if args[0] == "action_dispatch.callback" + if args[0] == "action_dispatch.callback" && !subscribers.empty? + flush_all! + log_tailer.tail! if tail_log + end end # Flush all subscribers' logger. -- cgit v1.2.3