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) ⇒ Object
- #enabled?(severity) ⇒ Boolean
- #error(event, **context) ⇒ Object
- #info(event, **context) ⇒ Object
-
#initialize(level:, output: $stdout, clock: -> { Time.now.utc }) ⇒ Logger
constructor
A new instance of Logger.
- #warn(event, **context) ⇒ Object
Constructor Details
#initialize(level:, output: $stdout, clock: -> { Time.now.utc }) ⇒ Logger
Returns a new instance of Logger.
15 16 17 18 19 20 |
# File 'lib/mammoth/logging.rb', line 15 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.
13 14 15 |
# File 'lib/mammoth/logging.rb', line 13 def clock @clock end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
13 14 15 |
# File 'lib/mammoth/logging.rb', line 13 def level @level end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
13 14 15 |
# File 'lib/mammoth/logging.rb', line 13 def output @output end |
Instance Method Details
#debug(event, **context) ⇒ Object
22 |
# File 'lib/mammoth/logging.rb', line 22 def debug(event, **context) = write("debug", event, context) |
#enabled?(severity) ⇒ Boolean
27 28 29 |
# File 'lib/mammoth/logging.rb', line 27 def enabled?(severity) LEVELS.fetch(severity.to_s) >= LEVELS.fetch(level) end |
#error(event, **context) ⇒ Object
25 |
# File 'lib/mammoth/logging.rb', line 25 def error(event, **context) = write("error", event, context) |
#info(event, **context) ⇒ Object
23 |
# File 'lib/mammoth/logging.rb', line 23 def info(event, **context) = write("info", event, context) |
#warn(event, **context) ⇒ Object
24 |
# File 'lib/mammoth/logging.rb', line 24 def warn(event, **context) = write("warn", event, context) |