aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/commands/server.rb6
-rw-r--r--railties/lib/rails/rack/log_tailer.rb4
-rw-r--r--railties/lib/rails/subscriber.rb14
3 files changed, 15 insertions, 9 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index b21ae2a17b..851a21c51d 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -46,6 +46,7 @@ module Rails
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
+ Rails::Subscriber.tail_log = true unless options[:daemonize]
super
ensure
puts 'Exiting' unless options[:daemonize]
@@ -53,15 +54,10 @@ module Rails
def middleware
middlewares = []
- middlewares << [Rails::Rack::LogTailer, log_path] unless options[:daemonize]
middlewares << [Rails::Rack::Debugger] if options[:debugger]
Hash.new(middlewares)
end
- def log_path
- "log/#{options[:environment]}.log"
- end
-
def default_options
super.merge({
:Port => 3000,
diff --git a/railties/lib/rails/rack/log_tailer.rb b/railties/lib/rails/rack/log_tailer.rb
index 077311be3c..3fa45156c3 100644
--- a/railties/lib/rails/rack/log_tailer.rb
+++ b/railties/lib/rails/rack/log_tailer.rb
@@ -13,11 +13,11 @@ module Rails
def call(env)
response = @app.call(env)
- tail_log
+ tail!
response
end
- def tail_log
+ def tail!
@file.seek @cursor
mod = @file.mtime.to_f
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.