Console::Logger (original) (raw)
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: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>V</mi><mi>E</mi><mi>R</mi><mi>B</mi><mi>O</mi><mi>S</mi><mi>E</mi><mo separator="true">,</mo><mi>d</mi><mi>e</mi><mi>b</mi><mi>u</mi><mi>g</mi><mo>:</mo></mrow><annotation encoding="application/x-tex">VERBOSE, debug: </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="mord mathnormal" style="margin-right:0.05764em;">ERBOSE</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.03588em;">ug</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span></span></span></span>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: <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>V</mi><mi>E</mi><mi>R</mi><mi>B</mi><mi>O</mi><mi>S</mi><mi>E</mi><mo separator="true">,</mo><mi>d</mi><mi>e</mi><mi>b</mi><mi>u</mi><mi>g</mi><mo>:</mo></mrow><annotation encoding="application/x-tex">VERBOSE, debug: </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8889em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.22222em;">V</span><span class="mord mathnormal" style="margin-right:0.05764em;">ERBOSE</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">d</span><span class="mord mathnormal">e</span><span class="mord mathnormal">b</span><span class="mord mathnormal" style="margin-right:0.03588em;">ug</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">:</span></span></span></span>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](../Output/index.html "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](../Progress/index.html "Console::Progress")
The progress indicator.
Implementation
def progress(subject, total, **options)
options[:severity] ||= :info
Progress.new(subject, total, **options)
end