Skip to content

Instantly share code, notes, and snippets.

@ryanwood
Last active November 28, 2018 15:31
Show Gist options
  • Save ryanwood/41c55feba11b41511a577e94ce2dda16 to your computer and use it in GitHub Desktop.
Save ryanwood/41c55feba11b41511a577e94ce2dda16 to your computer and use it in GitHub Desktop.
MultiLogger
# So we can log to STDOUT and a file at once. ;)
class MultiIO
def initialize(*targets)
@targets = targets
end
def write(*args)
@targets.each {|t| t.write(*args)}
end
def close
@targets.each(&:close)
end
end
require 'multi_io'
def logger
@logger ||= begin
log_file = File.open("my_log_file.log", "a")
target = MultiIO.new(STDOUT, log_file)
Logger.new(target)
end
end
# Use
logger.debug("Would have run: #{sql}")
logger.info('Checkpoint!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment