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
23
24
25
26
27
# File 'lib/delayed/log_tailer.rb', line 5

def run
  if Rails.logger.respond_to?(:broadcast_to)
    return if ActiveSupport::Logger.logger_outputs_to?(Rails.logger, $stdout)

    Rails.logger.broadcast_to(ActiveSupport::Logger.new($stdout))
    return
  elsif 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