Class: Console::Logger
- Inherits:
-
Object
- Object
- Console::Logger
- Extended by:
- Fiber::Local
- Defined in:
- lib/console/logger.rb
Constant Summary collapse
- DEFAULT_LEVEL =
1
Class Method Summary collapse
-
.default_log_level(env = ENV) ⇒ Object
Set the default log level based on ‘$DEBUG` and `$VERBOSE`.
- .default_logger(output = $stderr, env = ENV, **options) ⇒ Object
- .local ⇒ Object
-
.verbose?(env = ENV) ⇒ Boolean
Controls verbose output using ‘$VERBOSE`.
Instance Method Summary collapse
- #error(subject, *arguments, **options, &block) ⇒ Object
- #failure(subject, exception, **options) ⇒ Object
-
#initialize(output, **options) ⇒ Logger
constructor
A new instance of Logger.
- #progress(subject, total, **options) ⇒ Object
Constructor Details
#initialize(output, **options) ⇒ Logger
Returns a new instance of Logger.
63 64 65 |
# File 'lib/console/logger.rb', line 63 def initialize(output, **) super(output, **) 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.
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/console/logger.rb', line 23 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 |
.default_logger(output = $stderr, env = ENV, **options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/console/logger.rb', line 40 def self.default_logger(output = $stderr, env = ENV, **) if [:verbose].nil? [:verbose] = self.verbose?(env) end if [:level].nil? [:level] = self.default_log_level(env) end output = Output.new(output, env, **) logger = self.new(output, **) Resolver.default_resolver(logger) return logger end |
.local ⇒ Object
57 58 59 |
# File 'lib/console/logger.rb', line 57 def self.local self.default_logger end |
.verbose?(env = ENV) ⇒ Boolean
Controls verbose output using ‘$VERBOSE`.
36 37 38 |
# File 'lib/console/logger.rb', line 36 def self.verbose?(env = ENV) !$VERBOSE.nil? || env['CONSOLE_VERBOSE'] end |
Instance Method Details
#error(subject, *arguments, **options, &block) ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/console/logger.rb', line 73 def error(subject, *arguments, **, &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 [:event] = Event::Failure.for(exception) end super end |