Class: Rails::Rack::LogTailer
Constant Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, log = nil) ⇒ LogTailer
constructor
A new instance of LogTailer.
- #tail_log ⇒ Object
Constructor Details
#initialize(app, log = nil) ⇒ LogTailer
Returns a new instance of LogTailer.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rails/rack/log_tailer.rb', line 6 def initialize(app, log = nil) @app = app path = Pathname.new(log || EnvironmentLog).cleanpath @cursor = ::File.size(path) @last_checked = Time.now.to_f @file = ::File.open(path, 'r') end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 |
# File 'lib/rails/rack/log_tailer.rb', line 16 def call(env) response = @app.call(env) tail_log response end |
#tail_log ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails/rack/log_tailer.rb', line 22 def tail_log @file.seek @cursor mod = @file.mtime.to_f if mod > @last_checked contents = @file.read @last_checked = mod @cursor += contents.size $stdout.print contents end end |