Class: Sapience::Formatters::Json

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

Instance Attribute Summary

Attributes inherited from Base

#filter, #log_hooks, #name

Instance Method Summary collapse

Methods inherited from Base

#app_name, #default_formatter, #fast_tag, #host, #level, #level=, #payload, #pop_tags, #push_tags, #silence, #tagged, #tags, #with_payload

Methods included from LogMethods

#debug, #debug?, #error, #error!, #error?, #fatal, #fatal!, #fatal?, #info, #info?, #level_to_index, #log_with_exception, #log_with_level, #measure, #measure_debug, #measure_error, #measure_fatal, #measure_info, #measure_trace, #measure_warn, #trace, #trace?, #warn, #warn?

Constructor Details

#initialize(options = {}) ⇒ Json

Default JSON time format is ISO8601



7
8
9
10
11
# File 'lib/sapience/formatters/json.rb', line 7

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

Instance Method Details

#call(log, logger) ⇒ Object

Returns log messages in JSON format



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

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