Class: Mammoth::Logging::Logger
- Inherits:
-
Object
- Object
- Mammoth::Logging::Logger
- Defined in:
- lib/mammoth/logging.rb
Overview
Logger that emits one JSON object per line.
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
-
#debug(event, **context) ⇒ Boolean
Emit a debug event when debug logging is enabled.
- #enabled?(severity) ⇒ Boolean
-
#error(event, **context) ⇒ Boolean
Emit an error event.
-
#info(event, **context) ⇒ Boolean
Emit an informational event when info logging is enabled.
-
#initialize(level:, output: $stdout, clock: -> { Time.now.utc }) ⇒ Logger
constructor
A new instance of Logger.
-
#warn(event, **context) ⇒ Boolean
Emit a warning event when warn logging is enabled.
Constructor Details
#initialize(level:, output: $stdout, clock: -> { Time.now.utc }) ⇒ Logger
Returns a new instance of Logger.
16 17 18 19 20 21 |
# File 'lib/mammoth/logging.rb', line 16 def initialize(level:, output: $stdout, clock: -> { Time.now.utc }) @level = level.to_s @output = output @clock = clock raise ConfigurationError, "unsupported logging level: #{@level}" unless LEVELS.key?(@level) end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
14 15 16 |
# File 'lib/mammoth/logging.rb', line 14 def clock @clock end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
14 15 16 |
# File 'lib/mammoth/logging.rb', line 14 def level @level end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
14 15 16 |
# File 'lib/mammoth/logging.rb', line 14 def output @output end |
Instance Method Details
#debug(event, **context) ⇒ Boolean
Emit a debug event when debug logging is enabled.
28 |
# File 'lib/mammoth/logging.rb', line 28 def debug(event, **context) = write("debug", event, context) |
#enabled?(severity) ⇒ Boolean
51 52 53 |
# File 'lib/mammoth/logging.rb', line 51 def enabled?(severity) LEVELS.fetch(severity.to_s) >= LEVELS.fetch(level) end |
#error(event, **context) ⇒ Boolean
Emit an error event.
49 |
# File 'lib/mammoth/logging.rb', line 49 def error(event, **context) = write("error", event, context) |
#info(event, **context) ⇒ Boolean
Emit an informational event when info logging is enabled.
35 |
# File 'lib/mammoth/logging.rb', line 35 def info(event, **context) = write("info", event, context) |
#warn(event, **context) ⇒ Boolean
Emit a warning event when warn logging is enabled.
42 |
# File 'lib/mammoth/logging.rb', line 42 def warn(event, **context) = write("warn", event, context) |