mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #4528 from j-manu/log-tailer-fix
Fix for log tailer when the log file doesn't exist.
This commit is contained in:
commit
de41f5a979
1 changed files with 7 additions and 3 deletions
|
@ -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?
|
||||
|
|
Loading…
Reference in a new issue