class Logtail::Logger::Formatter

@private

Constants

EMPTY_ARRAY
SEVERITY_MAP

Formatters get the formatted level from the logger.

Private Instance Methods

build_log_entry(severity, time, progname, logged_obj) click to toggle source
# File lib/logtail/logger.rb, line 34
def build_log_entry(severity, time, progname, logged_obj)
  context_snapshot = CurrentContext.instance.snapshot
  level = SEVERITY_MAP.fetch(severity)
  tags = extract_active_support_tagged_logging_tags.clone

  if logged_obj.is_a?(Event)
    LogEntry.new(level, time, progname, logged_obj.message, context_snapshot, logged_obj,
                 tags: tags)
  elsif logged_obj.is_a?(Hash)
    # Extract the tags
    tags.push(logged_obj.delete(:tag)) if logged_obj.key?(:tag)
    tags.concat(logged_obj.delete(:tags)) if logged_obj.key?(:tags)
    tags.uniq!

    message = logged_obj.delete(:message)

    LogEntry.new(level, time, progname, message, context_snapshot, logged_obj, tags: tags)
  else
    LogEntry.new(level, time, progname, logged_obj, context_snapshot, nil, tags: tags)
  end
end
extract_active_support_tagged_logging_tags() click to toggle source

Because of all the crazy ways Rails has attempted tags, we need this crazy method.

# File lib/logtail/logger.rb, line 57
def extract_active_support_tagged_logging_tags
  @current_tags ||
    Thread.current[:activesupport_tagged_logging_tags] ||
    Thread.current[tagged_logging_object_key_name] ||
    EMPTY_ARRAY
end
tagged_logging_object_key_name() click to toggle source
# File lib/logtail/logger.rb, line 64
def tagged_logging_object_key_name
  @tagged_logging_object_key_name ||= "activesupport_tagged_logging_tags:#{object_id}"
end