Class: Rails::Rack::LogTailer

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/rack/log_tailer.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, log = nil) ⇒ LogTailer

Returns a new instance of LogTailer.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rails/rack/log_tailer.rb', line 6

def initialize(app, log = nil)
  ActiveSupport::Deprecation.warn('LogTailer is deprecated and will be removed on Rails 5.')

  @app = app

  path = Pathname.new(log || "#{::File.expand_path(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



20
21
22
23
24
# File 'lib/rails/rack/log_tailer.rb', line 20

def call(env)
  response = @app.call(env)
  tail!
  response
end

#tail!Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/rack/log_tailer.rb', line 26

def tail!
  return unless @cursor
  @file.seek @cursor

  unless @file.eof?
    contents = @file.read
    @cursor = @file.tell
    $stdout.print contents
  end
end