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

This commit is contained in:
Manu J 2012-01-19 01:42:37 +05:30
parent 423b2626d8
commit cf1f563473
1 changed files with 7 additions and 3 deletions

View File

@ -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?