Class: SemanticLogger::Formatters::Logfmt

Inherits:
Raw
  • Object
show all
Defined in:
lib/semantic_logger/formatters/logfmt.rb

Overview

Produces logfmt formatted messages

The following fields are extracted from the raw log and included in the formatted message:

:timestamp, :level, :name, :message, :duration, :tags, :named_tags

E.g.

timestamp="2020-07-20T08:32:05.375276Z" level=info name="DefaultTest" base="breakfast" spaces="second breakfast" double_quotes="\"elevensies\"" single_quotes="'lunch'" tag="success"

All timestamps are ISO8601 formatteed All user supplied values are escaped and surrounded by double quotes to avoid ambiguious message delimeters ‘tags` are treated as keys with boolean values. Tag names are not formatted or validated, ensure you use valid logfmt format for tag names. `named_tags` are flattened are merged into the top level message field. Any conflicting fields are overridden. `payload` values take precedence over `tags` and `named_tags`. Any conflicting fields are overridden.

Futher Reading brandur.org/logfmt

Instance Attribute Summary

Attributes inherited from Raw

#hash, #time_key

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Raw

#application, #duration, #environment, #exception, #file_name_and_line, #host, #level, #message, #metric, #name, #named_tags, #payload, #pid, #tags, #thread_name, #time

Methods inherited from Base

#backtrace, #fast_tag, #level, #level=, #log, #measure, #named_tags, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags

Constructor Details

#initialize(time_format: :iso_8601, time_key: :timestamp, **args) ⇒ Logfmt

Returns a new instance of Logfmt.



21
22
23
# File 'lib/semantic_logger/formatters/logfmt.rb', line 21

def initialize(time_format: :iso_8601, time_key: :timestamp, **args)
  super(time_format: time_format, time_key: time_key, **args)
end

Instance Method Details

#call(log, logger) ⇒ Object



25
26
27
28
29
# File 'lib/semantic_logger/formatters/logfmt.rb', line 25

def call(log, logger)
  @raw = super(log, logger)

  raw_to_logfmt
end