Class: Dragnet::CLI::Logger
- Inherits:
-
Object
- Object
- Dragnet::CLI::Logger
- Defined in:
- lib/dragnet/cli/logger.rb
Overview
A logger for the CLI. It uses the say
method in Thor's Shell
class to print the messages to the output, honoring the status of the quiet
command line switch.
Constant Summary collapse
- LEVELS =
{ debug: 0, info: 1, warn: 2, error: 3 }.freeze
- DEFAULT_LOG_LEVEL =
:info
- PADDING_STRING =
' '
- PADDING_WIDTH =
7
Instance Attribute Summary collapse
-
#log_level ⇒ Object
readonly
Returns the value of attribute log_level.
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Instance Method Summary collapse
-
#debug(message) ⇒ Object
Prints a message with log level
debug
. -
#error(message) ⇒ Object
Prints a message with log level
error
. -
#info(message) ⇒ Object
Prints a message with log level
info
. -
#initialize(shell, log_level = DEFAULT_LOG_LEVEL) ⇒ Logger
constructor
Creates a new instance of the class.
-
#warn(message) ⇒ Object
Prints a message with log level
warn
.
Constructor Details
#initialize(shell, log_level = DEFAULT_LOG_LEVEL) ⇒ Logger
Creates a new instance of the class.
25 26 27 28 29 30 |
# File 'lib/dragnet/cli/logger.rb', line 25 def initialize(shell, log_level = DEFAULT_LOG_LEVEL) raise ArgumentError, "Unknown logger level: #{log_level}" unless LEVELS.keys.include?(log_level) @log_level = LEVELS[log_level] @shell = shell end |
Instance Attribute Details
#log_level ⇒ Object (readonly)
Returns the value of attribute log_level.
11 12 13 |
# File 'lib/dragnet/cli/logger.rb', line 11 def log_level @log_level end |
#shell ⇒ Object (readonly)
Returns the value of attribute shell.
11 12 13 |
# File 'lib/dragnet/cli/logger.rb', line 11 def shell @shell end |
Instance Method Details
#debug(message) ⇒ Object
Prints a message with log level debug
34 35 36 |
# File 'lib/dragnet/cli/logger.rb', line 34 def debug() output(:debug, :green, ) end |
#error(message) ⇒ Object
Prints a message with log level error
52 53 54 |
# File 'lib/dragnet/cli/logger.rb', line 52 def error() output(:error, :red, ) end |
#info(message) ⇒ Object
Prints a message with log level info
40 41 42 |
# File 'lib/dragnet/cli/logger.rb', line 40 def info() output(:info, :blue, ) end |
#warn(message) ⇒ Object
Prints a message with log level warn
46 47 48 |
# File 'lib/dragnet/cli/logger.rb', line 46 def warn() output(:warn, :yellow, ) end |