class SemanticLoggerEcsAddon::Formatters::Raw

Public Class Methods

new(time_format: :none, time_key: :@timestamp, **args) click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 6
def initialize time_format: :none, time_key: :@timestamp, **args
  @time_key = time_key
  super(time_format: time_format, time_key: @time_key, **args)
end

Public Instance Methods

base() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 11
def base
  time
  labels
  message
  tags
end
call(log, logger) click to toggle source

Returns log messages in Hash format

# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 91
def call log, logger
  self.hash   = {}
  self.log    = log
  self.logger = logger
  format_payload

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

  hash.compact
end
ecs() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 18
def ecs
  hash[:"ecs.version"] = "1.10"
end
ecs_log() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 45
def ecs_log
  hash[:"log.level"] = calculated_log_level
  hash[:"log.logger"] = log.name
  file_name_and_line
end
ecs_process() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 51
def ecs_process
  hash[:"process.thread.name"] = log.thread_name
  hash[:"process.pid"] = pid
end
ecs_service() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 56
def ecs_service
  hash[:"service.name"] = logger.application
end
ecs_source() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 60
def ecs_source
  hash[:"source.ip"] = formatted_payload.delete :remote_ip
end
ecs_tracing() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 64
def ecs_tracing
  return unless apm_agent_present_and_running?

  hash[:"transaction.id"] = ElasticAPM.current_transaction&.id
  hash[:"trace.id"] = ElasticAPM.current_transaction&.trace_id
  hash[:"span.id"] = ElasticAPM.current_span&.id
end
ecs_url() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 72
def ecs_url
  hash[:"url.path"] = formatted_payload.dig :request, :path
end
ecs_user() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 76
def ecs_user
  hash[:"user.email"] = formatted_payload.dig :user, :email
  hash[:"user.full_name"] = formatted_payload.dig :user, :full_name
  hash[:"user.id"] = formatted_payload.dig :user, :id
  hash[:"user.name"] = formatted_payload.dig :user, :name
  hash[:"user.domain"] = formatted_payload.dig :user, :type
end
error() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 22
def error
  root = hash
  each_exception exception do |e, i|
    if i.zero?
      root.merge! exception_hash e
    else
      root[:"error.cause"] = exception_hash e
      root = root[:"error.cause"]
    end
  end
end
event() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 34
def event
  hash[:"event.dataset"] = "#{logger.application}.log"
  hash[:"event.duration"] = (log.duration || 0) * 1000000
  hash[:"event.outcome"] = error_log? ? "failure" : "success"
end
extras() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 84
def extras
  return unless formatted_payload.respond_to?(:empty?) && !formatted_payload.empty?

  hash.merge! formatted_payload.except(:request, :response, :user)
end
http() click to toggle source
# File lib/semantic_logger_ecs_addon/formatters/raw.rb, line 40
def http
  request
  response
end