aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-15 12:15:49 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-15 12:24:31 +0100
commit6487d2871cbd44d769c483f47130e18d53e6e381 (patch)
tree34984f58948bff46a188ea82b5dc799c3b8f1ab0
parent88dd60298ef393e2406ab543a1124a4304a19f61 (diff)
downloadrails-6487d2871cbd44d769c483f47130e18d53e6e381.tar.gz
rails-6487d2871cbd44d769c483f47130e18d53e6e381.tar.bz2
rails-6487d2871cbd44d769c483f47130e18d53e6e381.zip
Fix an issue where log was not being tailed in the first request.
-rw-r--r--railties/lib/rails/commands/server.rb15
-rw-r--r--railties/lib/rails/subscriber.rb11
-rw-r--r--railties/test/subscriber_test.rb5
3 files changed, 18 insertions, 13 deletions
diff --git a/railties/lib/rails/commands/server.rb b/railties/lib/rails/commands/server.rb
index 851a21c51d..115499db05 100644
--- a/railties/lib/rails/commands/server.rb
+++ b/railties/lib/rails/commands/server.rb
@@ -46,7 +46,7 @@ module Rails
trap(:INT) { exit }
puts "=> Ctrl-C to shutdown server" unless options[:daemonize]
- Rails::Subscriber.tail_log = true unless options[:daemonize]
+ initialize_log_tailer! unless options[:daemonize]
super
ensure
puts 'Exiting' unless options[:daemonize]
@@ -58,6 +58,10 @@ module Rails
Hash.new(middlewares)
end
+ def log_path
+ "log/#{options[:environment]}.log"
+ end
+
def default_options
super.merge({
:Port => 3000,
@@ -67,5 +71,14 @@ module Rails
:pid => "tmp/pids/server.pid"
})
end
+
+ protected
+
+ # LogTailer should not be used as a middleware since the logging happens
+ # async in a request and the middleware calls are sync. So we send it
+ # to subscriber which will be responsible for calling tail! in the log tailer.
+ def initialize_log_tailer!
+ Rails::Subscriber.log_tailer = Rails::Rack::LogTailer.new(nil, log_path)
+ end
end
end
diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/subscriber.rb
index 2c62f178b8..e8d13babf0 100644
--- a/railties/lib/rails/subscriber.rb
+++ b/railties/lib/rails/subscriber.rb
@@ -33,9 +33,8 @@ 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
- mattr_accessor :colorize_logging, :tail_log
+ mattr_accessor :colorize_logging, :log_tailer
self.colorize_logging = true
- self.tail_log = false
# Embed in a String to clear all previous ANSI sequences.
CLEAR = "\e[0m"
@@ -59,12 +58,6 @@ 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]
@@ -75,7 +68,7 @@ module Rails
if args[0] == "action_dispatch.callback" && !subscribers.empty?
flush_all!
- log_tailer.tail! if tail_log
+ log_tailer.tail! if log_tailer
end
end
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
index c45a68602d..ac34939510 100644
--- a/railties/test/subscriber_test.rb
+++ b/railties/test/subscriber_test.rb
@@ -108,14 +108,13 @@ module SubscriberTest
def test_tails_logs_when_action_dispatch_callback_is_received
log_tailer = mock()
log_tailer.expects(:tail!)
- Rails::Rack::LogTailer.expects(:new).with(nil, "log/development.log").returns(log_tailer)
+ Rails::Subscriber.log_tailer = log_tailer
- Rails::Subscriber.tail_log = true
Rails::Subscriber.add :my_subscriber, @subscriber
instrument "action_dispatch.callback"
wait
ensure
- Rails::Subscriber.tail_log = false
+ Rails::Subscriber.log_tailer = nil
end
class SyncSubscriberTest < ActiveSupport::TestCase