Module: CliLogger::Logger
- Included in:
- CliLogger
- Defined in:
- lib/cli_logger/logger.rb
Overview
Logger module
Instance Method Summary collapse
- #current_level ⇒ Object
- #current_level=(value) ⇒ Object
- #levels ⇒ Object
- #log(log_level, message) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
rubocop:enable Style/AccessorMethodName.
-
#set_options(*args) ⇒ Object
rubocop:disable Style/AccessorMethodName.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
rubocop:enable Style/AccessorMethodName
11 12 13 |
# File 'lib/cli_logger/logger.rb', line 11 def method_missing(name, *args, &block) log(name.to_sym, *args, &block) if levels.key?(name.to_sym) end |
Instance Method Details
#current_level ⇒ Object
30 31 32 |
# File 'lib/cli_logger/logger.rb', line 30 def current_level @current_level ||= levels[:info] end |
#current_level=(value) ⇒ Object
34 35 36 37 |
# File 'lib/cli_logger/logger.rb', line 34 def current_level=(value) validate_level(value) @current_level = levels[value] end |
#levels ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/cli_logger/logger.rb', line 39 def levels { error: 0, warning: 1, info: 2, debug: 3 } end |
#log(log_level, message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cli_logger/logger.rb', line 15 def log(log_level, ) validate_level(log_level) return unless levels[log_level] <= current_level = (log_level, ) if block_given? sublog do yield end += (log_level, 'DONE') end end |
#set_options(*args) ⇒ Object
rubocop:disable Style/AccessorMethodName
6 7 8 |
# File 'lib/cli_logger/logger.rb', line 6 def (*args) @options = args end |