class Console::Logger
def self.default_log_level(env = ENV)
You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
Set the default log level based on `$DEBUG` and `$VERBOSE`.
def self.default_log_level(env = ENV) if level = env['CONSOLE_LEVEL'] LEVELS[level.to_sym] || level.to_i elsif $DEBUG DEBUG elsif $VERBOSE.nil? WARN else INFO end end
def self.default_logger(output = $stderr, env = ENV, **options)
def self.default_logger(output = $stderr, env = ENV, **options) if options[:verbose].nil? options[:verbose] = self.verbose?(env) end if options[:level].nil? options[:level] = self.default_log_level(env) end output = Output.new(output, env, **options) logger = self.new(output, **options) Resolver.default_resolver(logger) return logger end
def self.local
def self.local self.default_logger end
def self.verbose?(env = ENV)
def self.verbose?(env = ENV) !$VERBOSE.nil? || env['CONSOLE_VERBOSE'] end
def error(subject, *arguments, **options, &block)
def error(subject, *arguments, **options, &block) # This is a special case where we want to create a failure event from an exception. # It's common to see `Console.error(self, exception)` in code. if arguments.first.is_a?(Exception) exception = arguments.shift options[:event] = Event::Failure.for(exception) end super end
def failure(subject, exception, **options)
def failure(subject, exception, **options) error(subject, event: Event::Failure.for(exception), **options) end
def initialize(output, **options)
def initialize(output, **options) super(output, **options) end
def progress(subject, total, **options)
def progress(subject, total, **options) options[:severity] ||= :info Progress.new(subject, total, **options) end