Class: SemanticLoggerEcsAddon::Formatters::Json

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

Instance Attribute Summary

Attributes inherited from Base

#formatted_payload, #hash, #log_labels, #time_key

Instance Method Summary collapse

Methods inherited from Raw

#base, #ecs, #ecs_log, #ecs_process, #ecs_service, #ecs_source, #ecs_tracing, #ecs_url, #ecs_user, #error, #event, #extras, #http, #safe_jsonify

Methods inherited from Base

#apm_agent_present_and_running?, #application, #calculated_log_level, #each_exception, #environment, #error_log?, #exception, #exception_hash, #file_name_and_line, #format_payload, #host, #initialize_rack_keys, #inner_exception, #labels, #message, #named_tags, #rack_extract, #rack_metrics, #rack_request, #rack_response, #request, #response, #tags, #time

Constructor Details

#initialize(time_format: :iso_8601, precision: 3, **args) ⇒ Json

Default JSON time format is ISO8601



9
10
11
# File 'lib/semantic_logger_ecs_addon/formatters/json.rb', line 9

def initialize time_format: :iso_8601, precision: 3, **args
  super(time_format: time_format, precision: precision, **args)
end

Instance Method Details

#call(log, logger) ⇒ Object

Returns log messages in JSON format



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

def call log, logger
  Oj.dump(super(log, logger), nilnil: true, escape_mode: :json, mode: :rails)
rescue SystemStackError => _error
  Oj.dump(super(log, logger).transform_keys {|key| key.to_s }, nilnil: true, escape_mode: :json, mode: :object)
end