Module: JsonTaggedLogging::Formatter

Includes:
ActiveSupport::TaggedLogging::Formatter
Defined in:
lib/json_tagged_logging/formatter.rb

Overview

:nodoc:

Constant Summary collapse

RESERVED_FIELDS =
%i[level timestamp app message trace]

Instance Method Summary collapse

Instance Method Details

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/json_tagged_logging/formatter.rb', line 10

def call(severity, timestamp, progname, msg)
  tags = tags_hash.except(*RESERVED_FIELDS)

  log = {
    level: severity,
    timestamp: timestamp.utc,
    app: progname
  }

  log.merge!(serialize_message(msg))
  log.merge!(tags)

  Oj.dump(log, mode: :compat) + "\n"
end

#tags_hashObject



25
26
27
28
29
30
31
# File 'lib/json_tagged_logging/formatter.rb', line 25

def tags_hash
  tags = current_tags.inject do |memo, value|
    value.is_a?(Hash) ? memo.merge(value) : memo
  end

  tags.is_a?(Hash) ? tags : {}
end