Class: Cabin::Outputs::StdlibLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/cabin/outputs/stdlib-logger.rb

Overview

Wrap Ruby stdlib’s logger. This allows you to output to a normal ruby logger with Cabin. Since Ruby’s Logger has a love for strings alone, this wrapper will convert the data/event to json before sending it to Logger.

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ StdlibLogger

Returns a new instance of StdlibLogger.



9
10
11
12
# File 'lib/cabin/outputs/stdlib-logger.rb', line 9

def initialize(logger)
  @logger = logger
  @logger.level = logger.class::DEBUG
end

Instance Method Details

#<<(data) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/cabin/outputs/stdlib-logger.rb', line 16

def <<(data)
  method = data[:level].downcase.to_sym || :info

  message = "#{data[:message]} #{data.to_json}"

  #p [@logger.level, logger.class::DEBUG]
  # This will call @logger.info(data) or something similar.
  @logger.send(method, message)
end