Class: Delayed::LogTailer

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

Instance Method Summary collapse

Instance Method Details

#runObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/delayed/log_tailer.rb', line 5

def run
  if Rails.logger.respond_to?(:log_path)
    log_path = Rails.logger.log_path
  elsif Rails.logger.instance_variable_get('@logdev').try(:instance_variable_get, '@dev').try(:path)
    log_path = Rails.logger.instance_variable_get('@logdev').instance_variable_get('@dev').path
  else
    return
  end
  Rails.logger.auto_flushing = true if Rails.logger.respond_to?(:auto_flushing=)
  Thread.new do
    f = File.open(log_path, 'r')
    f.seek(0, IO::SEEK_END)
    loop do
      content = f.read
      content.present? ? STDOUT.print(content) : sleep(0.5)
    end
  end
end