diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-20 10:23:46 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-04-27 08:51:29 -0700 |
commit | 05bee990b4bd0ce3b02e75399c857e168f41edb6 (patch) | |
tree | 9b6fec4c51244174be968277d1ece1ec1cfb3ef3 /railties/lib/rails/rack/log_tailer.rb | |
parent | 006de2577a978cd212f07df478b03053b1309c84 (diff) | |
download | rails-05bee990b4bd0ce3b02e75399c857e168f41edb6.tar.gz rails-05bee990b4bd0ce3b02e75399c857e168f41edb6.tar.bz2 rails-05bee990b4bd0ce3b02e75399c857e168f41edb6.zip |
Merge pull request #4528 from j-manu/log-tailer-fix
Fix for log tailer when the log file doesn't exist.
Diffstat (limited to 'railties/lib/rails/rack/log_tailer.rb')
-rw-r--r-- | railties/lib/rails/rack/log_tailer.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/railties/lib/rails/rack/log_tailer.rb b/railties/lib/rails/rack/log_tailer.rb index 830d840894..18f22e8089 100644 --- a/railties/lib/rails/rack/log_tailer.rb +++ b/railties/lib/rails/rack/log_tailer.rb @@ -4,10 +4,13 @@ module Rails def initialize(app, log = nil) @app = app - path = Pathname.new(log || "#{File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath - @cursor = ::File.size(path) + path = Pathname.new(log || "#{::File.expand_path(Rails.root)}/log/#{Rails.env}.log").cleanpath - @file = ::File.open(path, 'r') + @cursor = @file = nil + if ::File.exists?(path) + @cursor = ::File.size(path) + @file = ::File.open(path, 'r') + end end def call(env) @@ -17,6 +20,7 @@ module Rails end def tail! + return unless @cursor @file.seek @cursor unless @file.eof? |