Class: Epilog::Formatter

Inherits:
Object
  • Object
show all
Includes:
ContextFormatter
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

Methods included from ContextFormatter

#context, #pop_context, #push_context

Constructor Details

#initialize(options = {}) ⇒ Formatter

Returns a new instance of Formatter.



17
18
19
# File 'lib/epilog/log_formatter.rb', line 17

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

Instance Attribute Details

#datetime_formatObject



34
35
36
# File 'lib/epilog/log_formatter.rb', line 34

def datetime_format
  @datetime_format || DEFAULT_TIME_FORMAT
end

#filterObject (readonly)

Returns the value of attribute filter.



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

def filter
  @filter
end

Instance Method Details

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



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

def call(severity, time, progname, msg)
  log = base_log(severity, time, progname)
  log.merge!(context)
  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