Class: LtsvLogFormatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ LtsvLogFormatter

Returns a new instance of LtsvLogFormatter.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • time_key (String) — default: default: time
  • level_key (String) — default: default: level
  • message_key (String) — default: default: message


11
12
13
14
15
16
# File 'lib/ltsv_log_formatter.rb', line 11

def initialize(opts={})
  @opts = opts.map {|k, v| [k.to_sym, v] }.to_h # symbolize_keys
  @opts[:time_key]      = :time    unless @opts.has_key?(:time_key)
  @opts[:level_key]     = :level   unless @opts.has_key?(:level_key)
  @opts[:message_key] ||= :message
end

Instance Attribute Details

#optsObject (readonly)

for tests



5
6
7
# File 'lib/ltsv_log_formatter.rb', line 5

def opts
  @opts
end

Instance Method Details

#call(severity, time, progname, msg) ⇒ Object



18
19
20
# File 'lib/ltsv_log_formatter.rb', line 18

def call(severity, time, progname, msg)
  "#{format_time(time)}#{format_severity(severity)}#{format_message(msg)}\n"
end