class TinyCI::MultiLogger

This class allows logging to both `STDOUT` and to a file with a single call. @attr [Boolean] quiet Disables logging to STDOUT

Constants

FORMAT
LEVEL

Attributes

quiet[RW]

Public Class Methods

new(quiet: false, path: nil, paths: []) click to toggle source

Constructor

@param [Boolean] quiet Disables logging to STDOUT @param [String] path Location to write logfile to

# File lib/tinyci/multi_logger.rb, line 22
def initialize(quiet: false, path: nil, paths: [])
  @file_loggers = []
  add_output_path path
  paths.each { |p| add_output_path(p) }
  @quiet = quiet

  @stdout_logger = Logger.new($stdout)
  @stdout_logger.formatter = FORMAT
  @stdout_logger.level = LEVEL
end

Public Instance Methods

add_output_path(path) click to toggle source
# File lib/tinyci/multi_logger.rb, line 41
def add_output_path(path)
  return unless path

  FileUtils.touch path

  logger = Logger.new(path)
  logger.formatter = FORMAT
  logger.level = LEVEL
  @file_loggers << logger

  logger
end
targets() click to toggle source
# File lib/tinyci/multi_logger.rb, line 33
def targets
  logs = []
  logs += @file_loggers
  logs << @stdout_logger unless @quiet

  logs
end