Class: SemanticLogger::Formatters::Json

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

Instance Attribute Summary

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Base

#fast_tag, #level, #level=, #measure, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload

Constructor Details

#initialize(options = {}) ⇒ Json

Default JSON time format is ISO8601



6
7
8
9
10
# File 'lib/semantic_logger/formatters/json.rb', line 6

def initialize(options = {})
  options               = options.dup
  options[:time_format] = :iso_8601 unless options.has_key?(:time_format)
  super(options)
end

Instance Method Details

#call(log, logger) ⇒ Object

Returns log messages in JSON format



13
14
15
16
17
18
# File 'lib/semantic_logger/formatters/json.rb', line 13

def call(log, logger)
  h = super(log, logger)
  h.delete(:time)
  h[:timestamp] = format_time(log.time)
  h.to_json
end