Permalink
Browse files

Merge pull request #4528 from j-manu/log-tailer-fix

Fix for log tailer when the log file doesn't exist.
  • Loading branch information...
tenderlove committed Jan 20, 2012
2 parents 8c2dc4c + cf1f563 commit de41f5a9799cbce276ca9c439c99f4377191b36d
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
- @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 de41f5a

Please sign in to comment.