class SemanticLogger::Formatters::Raw

Attributes

hash[RW]

Fields are added by populating this hash.

time_key[RW]

Fields are added by populating this hash.

Public Class Methods

new(time_format: :none, time_key: :time, **args) click to toggle source

By default Raw formatter does not reformat the time

Calls superclass method SemanticLogger::Formatters::Base::new
# File lib/semantic_logger/formatters/raw.rb, line 9
def initialize(time_format: :none, time_key: :time, **args)
  @time_key = time_key
  super(time_format: time_format, **args)
end

Public Instance Methods

application() click to toggle source

Application name

# File lib/semantic_logger/formatters/raw.rb, line 20
def application
  hash[:application] = logger.application if log_application && logger && logger.application
end
call(log, logger) click to toggle source

Returns log messages in Hash format

# File lib/semantic_logger/formatters/raw.rb, line 115
def call(log, logger)
  self.hash   = {}
  self.log    = log
  self.logger = logger

  host
  application
  environment
  time
  level
  pid
  thread_name
  file_name_and_line
  duration
  tags
  named_tags
  name
  message
  payload
  exception
  metric

  hash
end
duration() click to toggle source

Duration

# File lib/semantic_logger/formatters/raw.rb, line 70
def duration
  return unless log.duration

  hash[:duration_ms] = log.duration
  hash[:duration]    = log.duration_human
end
environment() click to toggle source

Environment

# File lib/semantic_logger/formatters/raw.rb, line 25
def environment
  hash[:environment] = logger.environment if log_environment && logger && logger.environment
end
exception() click to toggle source

Exception

# File lib/semantic_logger/formatters/raw.rb, line 93
def exception
  return unless log.exception

  root = hash
  log.each_exception do |exception, i|
    name       = i.zero? ? :exception : :cause
    root[name] = {
      name:        exception.class.name,
      message:     exception.message,
      stack_trace: exception.backtrace
    }
    root = root[name]
  end
end
file_name_and_line() click to toggle source

Ruby file name and line number that logged the message.

# File lib/semantic_logger/formatters/raw.rb, line 51
def file_name_and_line
  file, line = log.file_name_and_line
  return unless file

  hash[:file] = file
  hash[:line] = line.to_i
end
host() click to toggle source

Host name

# File lib/semantic_logger/formatters/raw.rb, line 15
def host
  hash[:host] = logger.host if log_host && logger.host
end
level() click to toggle source

Log level

# File lib/semantic_logger/formatters/raw.rb, line 35
def level
  hash[:level]       = log.level
  hash[:level_index] = log.level_index
end
message() click to toggle source

Log message

# File lib/semantic_logger/formatters/raw.rb, line 83
def message
  hash[:message] = log.cleansed_message if log.message
end
metric() click to toggle source

Metric

# File lib/semantic_logger/formatters/raw.rb, line 109
def metric
  hash[:metric]        = log.metric if log.metric
  hash[:metric_amount] = log.metric_amount if log.metric_amount
end
name() click to toggle source

Class / app name

# File lib/semantic_logger/formatters/raw.rb, line 78
def name
  hash[:name] = log.name
end
named_tags() click to toggle source

Named Tags

# File lib/semantic_logger/formatters/raw.rb, line 65
def named_tags
  hash[:named_tags] = log.named_tags if log.named_tags && !log.named_tags.empty?
end
payload() click to toggle source

Payload

# File lib/semantic_logger/formatters/raw.rb, line 88
def payload
  hash[:payload] = log.payload if log.payload&.respond_to?(:empty?) && !log.payload.empty?
end
pid() click to toggle source

Process ID

Calls superclass method SemanticLogger::Formatters::Base#pid
# File lib/semantic_logger/formatters/raw.rb, line 41
def pid
  hash[:pid] = super
end
tags() click to toggle source

Tags

# File lib/semantic_logger/formatters/raw.rb, line 60
def tags
  hash[:tags] = log.tags if log.tags && !log.tags.empty?
end
thread_name() click to toggle source

Name of the thread that logged the message.

# File lib/semantic_logger/formatters/raw.rb, line 46
def thread_name
  hash[:thread] = log.thread_name
end
time() click to toggle source

Date & time

# File lib/semantic_logger/formatters/raw.rb, line 30
def time
  hash[time_key] = format_time(log.time)
end