Permalink
Browse files

Fix for log tailer when the log file doesn't exist.

  • Loading branch information...
1 parent 423b262 commit cf1f563473369c02917608e9b4c461328b6f8dac @j-manu j-manu committed Jan 18, 2012
Showing with 7 additions and 3 deletions.
  1. +7 −3 railties/lib/rails/rack/log_tailer.rb
@@ -4,10 +4,13 @@ class LogTailer
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
aceofspades
aceofspades May 18, 2012

Noticing that the log path is defined both here and in Rails::Application::Configuration#paths. Any reason?

drogus
drogus May 18, 2012 Member

Nope, no reason. It should use paths from app config to allow to change it easily (this is hardcoded which is bad). Good catch, please submit a pull request if you would like to fix it. If no, please ping me or open an issue, thanks!

- @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 @@ def call(env)
end
def tail!
+ return unless @cursor
@file.seek @cursor
unless @file.eof?

0 comments on commit cf1f563

Please sign in to comment.