class Lumberjack::LogEntry

An entry in a log is a data structure that captures the log message as well as information about the system that logged the message.

Constants

TIME_FORMAT
UNIT_OF_WORK_ID

Attributes

message[RW]
pid[RW]
progname[RW]
severity[RW]
tags[RW]
time[RW]

Public Class Methods

new(time, severity, message, progname, pid, tags) click to toggle source
# File lib/lumberjack/log_entry.rb, line 13
def initialize(time, severity, message, progname, pid, tags)
  @time = time
  @severity = (severity.is_a?(Integer) ? severity : Severity.label_to_level(severity))
  @message = message
  @progname = progname
  @pid = pid
  # backward compatibility with 1.0 API where the last argument was the unit of work id
  @tags = if tags.nil? || tags.is_a?(Hash)
    tags
  else
    {UNIT_OF_WORK_ID => tags}
  end
end

Public Instance Methods

inspect() click to toggle source
# File lib/lumberjack/log_entry.rb, line 35
def inspect
  to_s
end
severity_label() click to toggle source
# File lib/lumberjack/log_entry.rb, line 27
def severity_label
  Severity.level_to_label(severity)
end
tag(name) click to toggle source

Return the tag with the specified name.

# File lib/lumberjack/log_entry.rb, line 54
def tag(name)
  tags[name.to_s] if tags
end
to_s() click to toggle source
# File lib/lumberjack/log_entry.rb, line 31
def to_s
  "[#{time.strftime(TIME_FORMAT)}.#{(time.usec / 1000.0).round.to_s.rjust(3, "0")} #{severity_label} #{progname}(#{pid})#{tags_to_s}] #{message}"
end
unit_of_work_id() click to toggle source

Deprecated - backward compatibility with 1.0 API

# File lib/lumberjack/log_entry.rb, line 40
def unit_of_work_id
  tags[UNIT_OF_WORK_ID] if tags
end
unit_of_work_id=(value) click to toggle source

Deprecated - backward compatibility with 1.0 API

# File lib/lumberjack/log_entry.rb, line 45
def unit_of_work_id=(value)
  if tags
    tags[UNIT_OF_WORK_ID] = value
  else
    @tags = {UNIT_OF_WORK_ID => value}
  end
end

Private Instance Methods

tags_to_s() click to toggle source
# File lib/lumberjack/log_entry.rb, line 60
def tags_to_s
  tags_string = ""
  tags&.each { |name, value| tags_string << " #{name}:#{value.inspect}" }
  tags_string
end