module GtfsReader::Log

Public Class Methods

debug(*args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 7
def debug(*args, &block)
  log(:debug, *args, &block)
end
error(*args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 19
def error(*args, &block)
  log(:error, *args, &block)
end
fatal(*args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 23
def fatal(*args, &block)
  log(:fatal, *args, &block)
end
info(*args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 11
def info(*args, &block)
  log(:info,  *args, &block)
end
level() click to toggle source
# File lib/gtfs_reader/log.rb, line 49
def level
  logger.level
end
level=(lev) click to toggle source
# File lib/gtfs_reader/log.rb, line 37
def level=(lev)
  logger.level =
    case lev
    when :debug then Logger::DEBUG
    when :info  then Logger::INFO
    when :warn  then Logger::WARN
    when :error then Logger::ERROR
    when :fatal then Logger::FATAL
    else raise "unknown log level '#{lev}'"
    end
end
log(level, *args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 27
def log(level, *args, &block)
  logger.send(level, *args, &block)
  nil
end
logger() { || ... } click to toggle source
# File lib/gtfs_reader/log.rb, line 32
def logger
  @logger = yield if block_given?
  @logger ||= create_logger
end
quiet() { || ... } click to toggle source

Silence the logger for the duration of the given block

# File lib/gtfs_reader/log.rb, line 54
def quiet
  old_logger = @logger
  begin
    @logger = NoOpLogger.new
    yield
  ensure
    @logger = old_logger
  end
end
warn(*args, &block) click to toggle source
# File lib/gtfs_reader/log.rb, line 15
def warn(*args, &block)
  log(:warn,  *args, &block)
end

Private Class Methods

create_logger() click to toggle source
# File lib/gtfs_reader/log.rb, line 66
def create_logger
  Logger.new($stderr).tap do |log|
    log.level = Logger::INFO
    log.debug { 'Starting GtfsReader...'.underline.colorize(:yellow) }
  end
end