Class: KineticSdk::Utils::KLogger
- Inherits:
-
Object
- Object
- KineticSdk::Utils::KLogger
- Defined in:
- lib/kinetic_sdk/utils/logger.rb
Overview
The KLogger class provides methods to output at different levels based on
a configuration property. The default log level is off
, but can be
turned on by passing in the log_level
option.
Available Levels: debug
, info
, warn
, error
, off
The default output is to STDOUT
, but can also be set to STDERR
by
passing in the log_output
option.
Available Outputs: STDOUT
, STDERR
Instance Method Summary collapse
-
#debug(msg) ⇒ Object
Print the message if level is Logger::DEBUG or lower.
-
#debug? ⇒ Boolean
Is the current log level set to Logger::DEBUG or lower?.
-
#error(msg) ⇒ Object
Print the message if level is Logger::ERROR or lower.
-
#error? ⇒ Boolean
Is the current log level set to Logger::ERROR or lower?.
-
#fatal(msg) ⇒ Object
Print the message if level is Logger::FATAL or lower.
-
#fatal? ⇒ Boolean
Is the current log level set to Logger::FATAL or lower?.
-
#info(msg) ⇒ Object
Print the message if level is Logger::INFO or lower.
-
#info? ⇒ Boolean
Is the current log level set to Logger::INFO or lower?.
-
#initialize(level, output = "stdout") ⇒ KLogger
constructor
Constructor.
-
#level ⇒ Integer
Get the logger level.
-
#warn(msg) ⇒ Object
Print the message if level is Logger::WARN or lower.
-
#warn? ⇒ Boolean
Is the current log level set to Logger::WARN or lower?.
Constructor Details
#initialize(level, output = "stdout") ⇒ KLogger
Constructor
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 23 def initialize(level, output="stdout") log_level = level.to_s.downcase log_output = output.to_s.downcase == "stderr" ? STDERR : STDOUT @logger = Logger.new(log_output) case log_level when "error" @logger.level= Logger::ERROR when "warn" @logger.level= Logger::WARN when "info" @logger.level= Logger::INFO when "debug" @logger.level= Logger::DEBUG else @logger.level= Logger::FATAL end # define the string output format @logger.formatter = proc do |severity, datetime, progname, msg| date_format = datetime.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ") "[#{date_format}] #{severity}: #{msg}\n" end end |
Instance Method Details
#debug(msg) ⇒ Object
Print the message if level is Logger::DEBUG or lower
52 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 52 def debug(msg); @logger.debug(msg); end |
#debug? ⇒ Boolean
Is the current log level set to Logger::DEBUG or lower?
57 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 57 def debug?; @logger.debug? end |
#error(msg) ⇒ Object
Print the message if level is Logger::ERROR or lower
62 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 62 def error(msg); @logger.error(msg); end |
#error? ⇒ Boolean
Is the current log level set to Logger::ERROR or lower?
67 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 67 def error?; @logger.error? end |
#fatal(msg) ⇒ Object
Print the message if level is Logger::FATAL or lower
72 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 72 def fatal(msg); @logger.fatal(msg); end |
#fatal? ⇒ Boolean
Is the current log level set to Logger::FATAL or lower?
77 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 77 def fatal?; @logger.fatal? end |
#info(msg) ⇒ Object
Print the message if level is Logger::INFO or lower
82 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 82 def info(msg); @logger.info(msg); end |
#info? ⇒ Boolean
Is the current log level set to Logger::INFO or lower?
87 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 87 def info?; @logger.info? end |
#level ⇒ Integer
Get the logger level
102 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 102 def level; @logger.level; end |
#warn(msg) ⇒ Object
Print the message if level is Logger::WARN or lower
92 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 92 def warn(msg); @logger.warn(msg); end |
#warn? ⇒ Boolean
Is the current log level set to Logger::WARN or lower?
97 |
# File 'lib/kinetic_sdk/utils/logger.rb', line 97 def warn?; @logger.warn?; end |