class Sapience::Formatters::Json
Public Class Methods
new(options = {})
click to toggle source
Default
JSON time format is ISO8601
Calls superclass method
# 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
Public Instance Methods
call(log, logger)
click to toggle source
Returns log messages in JSON format
Calls superclass method
# File lib/sapience/formatters/json.rb, line 14 def call(log, logger) h = super(log, logger) prepare(h, log).to_json end
Private Instance Methods
prepare(log_hash, log)
click to toggle source
# File lib/sapience/formatters/json.rb, line 21 def prepare(log_hash, log) set_timestamp(log_hash, log) remove_fields(log_hash) log_hash end
remove_fields(log_hash)
click to toggle source
# File lib/sapience/formatters/json.rb, line 33 def remove_fields(log_hash) log_hash.delete_if { |k, _v| exclude_fields.include?(k.to_sym) } if exclude_fields.any? end
set_timestamp(log_hash, log)
click to toggle source
# File lib/sapience/formatters/json.rb, line 27 def set_timestamp(log_hash, log) log_hash.delete(:time) log_hash[:timestamp] = format_time(log.time) log_hash end