Class: Dry::Logger::Formatters::JSON

Inherits:
Structured
  • Object
show all
Defined in:
lib/dry/logger/formatters/json.rb

Overview

JSON formatter.

This formatter returns log entries in JSON format.

Since:

  • 0.1.0

Constant Summary

Constants inherited from Structured

Structured::DEFAULT_FILTERS, Structured::NOOP_FILTER

Instance Attribute Summary

Attributes inherited from Structured

#filter, #options

Instance Method Summary collapse

Methods inherited from Structured

#call, #format_values, #initialize

Constructor Details

This class inherits a constructor from Dry::Logger::Formatters::Structured

Instance Method Details

#format(entry) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



20
21
22
23
24
# File 'lib/dry/logger/formatters/json.rb', line 20

def format(entry)
  hash = format_values(entry).compact
  hash.update(hash.delete(:exception)) if entry.exception?
  ::JSON.dump(hash)
end

#format_exception(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



34
35
36
37
38
39
40
# File 'lib/dry/logger/formatters/json.rb', line 34

def format_exception(value)
  {
    exception: value.class,
    message: value.message,
    backtrace: value.backtrace || EMPTY_ARRAY
  }
end

#format_severity(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



28
29
30
# File 'lib/dry/logger/formatters/json.rb', line 28

def format_severity(value)
  value.upcase
end

#format_time(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0



44
45
46
# File 'lib/dry/logger/formatters/json.rb', line 44

def format_time(value)
  value.getutc.iso8601
end