imap.rb/lib/local_logger.rb

32 lines
508 B
Ruby

require "logger"
class MultiIO
def initialize(*targets)
@targets = targets
end
def <<(io)
@targets << io unless io == self
self
end
def write(*args)
@targets.each { _1.write(*args) }
self
end
def close
@targets.each(&:close)
end
end
log_output = MultiIO.new($stdout)
if ENV["LOG_FILE"]
log_file = File.open(ENV["LOG_FILE"], "a")
log_output << log_file
end
$logger = Logger.new(log_output)
$logger.level = Logger::INFO
$logger.level = Logger::DEBUG if $debug