Class: Epilog::Formatter

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

Constant Summary collapse

SEVERITY_MAP =
{
  'FATAL' => 'ALERT',
  'WARN' => 'WARNING'
}.freeze
DEFAULT_TIME_FORMAT =
'%Y-%m-%dT%H:%M:%S%z'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Formatter

Returns a new instance of Formatter.



15
16
17
# File 'lib/epilog/log_formatter.rb', line 15

def initialize(options = {})
  @filter = options[:filter] || Filter::Blacklist.new
end

Instance Attribute Details

#datetime_formatObject



31
32
33
# File 'lib/epilog/log_formatter.rb', line 31

def datetime_format
  @datetime_format || DEFAULT_TIME_FORMAT
end

#filterObject (readonly)

Returns the value of attribute filter.



12
13
14
# File 'lib/epilog/log_formatter.rb', line 12

def filter
  @filter
end

Instance Method Details

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



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/epilog/log_formatter.rb', line 19

def call(severity, time, progname, msg)
  log = base_log(severity, time, progname)
  log.merge!(message(msg))

  if log[:exception].is_a?(Exception)
    log[:exception] = format_error(log[:exception])
  end

  log = before_write(log)
  "#{JSON.dump(log)}\n"
end