Class: ConsoleLogger
- Inherits:
-
Logger
- Object
- Logger
- ConsoleLogger
- Defined in:
- lib/apimatic-core/logger/default_logger.rb
Overview
Represents a logger implementation that logs messages to the console.
Instance Method Summary collapse
- #format_log_message(severity, _datetime, _progname, msg) ⇒ Object
-
#initialize ⇒ ConsoleLogger
constructor
Initializes a new instance of DefaultLogger.
-
#log(level, message, params = {}) ⇒ Object
Logs a message to the console with the specified log level.
- #message_with_params(message, params) ⇒ Object
Constructor Details
#initialize ⇒ ConsoleLogger
Initializes a new instance of DefaultLogger.
4 5 6 7 |
# File 'lib/apimatic-core/logger/default_logger.rb', line 4 def initialize @logger = ::Logger.new($stdout) @logger.formatter = method(:format_log_message) end |
Instance Method Details
#format_log_message(severity, _datetime, _progname, msg) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/apimatic-core/logger/default_logger.rb', line 31 def (severity, _datetime, _progname, msg) "#{ severity.ljust(5) + msg }\n" end |
#log(level, message, params = {}) ⇒ Object
Logs a message to the console with the specified log level.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/apimatic-core/logger/default_logger.rb', line 13 def log(level, , params = {}) = (, params) case level when Logger::DEBUG @logger.debug() when Logger::INFO @logger.info() when Logger::WARN @logger.warn() when Logger::ERROR @logger.error() when Logger::FATAL @logger.fatal() else @logger.unknown() end end |
#message_with_params(message, params) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/apimatic-core/logger/default_logger.rb', line 38 def (, params) .gsub(/\{([\w-]+)\}/) do |match| key = match[1..-2] params[key.to_sym] || params[key.to_s] end end |