Class: JsonLogging::Formatter

Inherits:
Logger::Formatter
  • Object
show all
Defined in:
lib/json_logging/formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tags: []) ⇒ Formatter

Returns a new instance of Formatter.



3
4
5
6
# File 'lib/json_logging/formatter.rb', line 3

def initialize(tags: [])
  super()
  @tags = Sanitizer.prepare_tags(tags)
end

Instance Attribute Details

#tagsObject (readonly)

Returns the value of attribute tags.



8
9
10
# File 'lib/json_logging/formatter.rb', line 8

def tags
  @tags
end

Instance Method Details

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



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

def call(severity, timestamp, progname, msg)
  LineEncoder.build_line(
    msg: msg,
    severity: severity,
    timestamp: Helpers.normalize_timestamp(timestamp),
    tags: @tags,
    additional_context: JsonLogging.additional_context_for_payload,
    additional_context_sanitized: true,
    sanitize_tags: false
  )
rescue => e
  build_fallback_output(severity, timestamp, msg, e)
end