class Logger
The standard logger interface with support for log levels and verbosity.
The log levels are: debug
, info
, warn
, error
, and fatal
.
Definitions
def self.default_log_level(env = ENV, verbose: $VERBOSE, debug: $DEBUG)
Set the default log level based on $DEBUG
and $VERBOSE
.
You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
Signature
-
parameter
env
Hash
The environment to read the log level from.
-
parameter
verbose
Boolean
The verbose flag.
-
parameter
debug
Boolean
The debug flag.
-
returns
Integer
The default log level.
Implementation
def self.default_log_level(env = ENV, verbose: $VERBOSE, debug: $DEBUG)
if level = env["CONSOLE_LEVEL"]
LEVELS[level.to_sym] || level.to_i
elsif debug
DEBUG
elsif verbose.nil?
WARN
else
INFO
end
end
def initialize(output, **options)
Create a new logger.
Signature
-
parameter
output
Console::Output
The output destination.
-
parameter
options
Hash
Additional options.
Implementation
def initialize(output, **options)
# This is the expected default behaviour, but it may be nice to have a way to override it.
output = Output::Failure.new(output, **options)
super(output, **options)
end
def progress(subject, total, **options)
Create a progress indicator for the given subject.
Signature
-
parameter
subject
String
The subject of the progress indicator.
-
parameter
total
Integer
The total number of items to process.
-
parameter
options
Hash
Additional options passed to
class Console::Progress
.-
returns
Progress
The progress indicator.
Implementation
def progress(subject, total, **options)
options[:severity] ||= :info
Progress.new(subject, total, **options)
end