Class: Console::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/console/logger.rb

Overview

The standard logger interface with support for log levels and verbosity.

The log levels are: ‘debug`, `info`, `warn`, `error`, and `fatal`.

Constant Summary collapse

DEFAULT_LEVEL =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, **options) ⇒ Logger

Create a new logger.



47
48
49
50
51
52
# File 'lib/console/logger.rb', line 47

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

Class Method Details

.default_log_level(env = ENV, verbose: $VERBOSE, debug: $DEBUG) ⇒ Object

Set the default log level based on ‘$DEBUG` and `$VERBOSE`. You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment. mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/console/logger.rb', line 29

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

Instance Method Details

#progress(subject, total, **options) ⇒ Object

Create a progress indicator for the given subject.



60
61
62
63
64
# File 'lib/console/logger.rb', line 60

def progress(subject, total, **options)
	options[:severity] ||= :info
	
	Progress.new(subject, total, **options)
end