Class: Mammoth::Logging::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/mammoth/logging.rb

Overview

Logger that emits one JSON object per line.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level:, output: $stdout, clock: -> { Time.now.utc }) ⇒ Logger

Returns a new instance of Logger.

Raises:



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

#clockObject (readonly)

Returns the value of attribute clock.



13
14
15
# File 'lib/mammoth/logging.rb', line 13

def clock
  @clock
end

#levelObject (readonly)

Returns the value of attribute level.



13
14
15
# File 'lib/mammoth/logging.rb', line 13

def level
  @level
end

#outputObject (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

Returns:

  • (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)