Class: Console::Logger

Inherits:
Object
  • Object
show all
Extended by:
Fiber::Local
Defined in:
lib/console/logger.rb

Constant Summary collapse

DEFAULT_LEVEL =
1

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output, **options) ⇒ Logger

Returns a new instance of Logger.


68
69
70
# File 'lib/console/logger.rb', line 68

def initialize(output, **options)
	super(output, **options)
end

Class Method Details

.default_log_level(env = ENV) ⇒ 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.


36
37
38
39
40
41
42
43
44
45
46
# File 'lib/console/logger.rb', line 36

def self.default_log_level(env = ENV)
	if level = (env['CONSOLE_LEVEL'] || env['CONSOLE_LOG_LEVEL'])
		LEVELS[level.to_sym] || level.to_i
	elsif $DEBUG
		DEBUG
	elsif $VERBOSE.nil?
		WARN
	else
		INFO
	end
end

.default_logger(output, verbose: self.verbose?, level: self.default_log_level) ⇒ Object


53
54
55
56
57
58
59
60
# File 'lib/console/logger.rb', line 53

def self.default_logger(output, verbose: self.verbose?, level: self.default_log_level)
	terminal = Terminal::Logger.new(output, verbose: verbose)
	
	logger = self.new(terminal, verbose: verbose, level: level)
	resolver = Resolver.default_resolver(logger)
	
	return logger
end

.localObject


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

def self.local
	self.default_logger($stderr)
end

.verbose?(env = ENV) ⇒ Boolean

Controls verbose output using `$VERBOSE`.

Returns:

  • (Boolean)

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

def self.verbose?(env = ENV)
	!$VERBOSE.nil? || env['CONSOLE_VERBOSE']
end

Instance Method Details

#failure(subject, exception, *arguments, &block) ⇒ Object


79
80
81
# File 'lib/console/logger.rb', line 79

def failure(subject, exception, *arguments, &block)
	fatal(subject, *arguments, Event::Failure.new(exception), &block)
end

#progress(subject, total, **options) ⇒ Object Also known as: measure


72
73
74
# File 'lib/console/logger.rb', line 72

def progress(subject, total, **options)
	Progress.new(self, subject, total, **options)
end