Class: Rails::Rack::LogTailer
- Defined in:
- railties/lib/rails/rack/log_tailer.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, log = nil) ⇒ LogTailer
constructor
A new instance of LogTailer.
- #tail! ⇒ Object
Constructor Details
#initialize(app, log = nil) ⇒ LogTailer
Returns a new instance of LogTailer.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'railties/lib/rails/rack/log_tailer.rb', line 4 def initialize(app, log = nil) @app = app path = Pathname.new(log || "#{::File.(Rails.root)}/log/#{Rails.env}.log").cleanpath @cursor = @file = nil if ::File.exist?(path) @cursor = ::File.size(path) @file = ::File.open(path, 'r') end end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 |
# File 'railties/lib/rails/rack/log_tailer.rb', line 16 def call(env) response = @app.call(env) tail! response end |
#tail! ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'railties/lib/rails/rack/log_tailer.rb', line 22 def tail! return unless @cursor @file.seek @cursor unless @file.eof? contents = @file.read @cursor = @file.tell $stdout.print contents end end |