Module: CommandLineBoss::LoggerOptions

Defined in:
lib/command_line_boss/logger_options.rb

Overview

Add --debug and --verbose options and a logger method

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#debugBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

true if the --debug option was given

Returns:

  • (Boolean)


12
13
14
# File 'lib/command_line_boss/logger_options.rb', line 12

def debug
  @debug
end

#verboseBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

true if the --verbose option was given

Returns:

  • (Boolean)


20
21
22
# File 'lib/command_line_boss/logger_options.rb', line 20

def verbose
  @verbose
end

Instance Method Details

#loggerLogger

The logger to use to report progress

Messages are logged at info and debug levels. The logger returned is one of the following:

  • A logger that logs to the console at the :info level if verbose mode is enabled
  • A logger that logs to the console at the :debug level if debug mode is enabled
  • Otherwise a null logger that does not log anything

Examples:

options.logger #=> #<Logger:0x00007f9e3b8b3e08>

Returns:

  • (Logger)


36
37
38
39
40
41
42
43
44
45
# File 'lib/command_line_boss/logger_options.rb', line 36

def logger
  @logger ||=
    if verbose
      verbose_logger
    elsif debug
      debug_logger
    else
      Logger.new(nil, level: Logger::UNKNOWN + 1)
    end
end