Class: Lumberjack::LogEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/lumberjack/log_entry.rb

Overview

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.

Constant Summary collapse

TIME_FORMAT =
"%Y-%m-%dT%H:%M:%S".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, severity, message, progname, pid, unit_of_work_id) ⇒ LogEntry

Returns a new instance of LogEntry.



9
10
11
12
13
14
15
16
# File 'lib/lumberjack/log_entry.rb', line 9

def initialize(time, severity, message, progname, pid, unit_of_work_id)
  @time = time
  @severity = (severity.is_a?(Fixnum) ? severity : Severity.label_to_level(severity))
  @message = message
  @progname = progname
  @pid = pid
  @unit_of_work_id = unit_of_work_id
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def message
  @message
end

#pidObject

Returns the value of attribute pid.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def pid
  @pid
end

#prognameObject

Returns the value of attribute progname.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def progname
  @progname
end

#severityObject

Returns the value of attribute severity.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def severity
  @severity
end

#timeObject

Returns the value of attribute time.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def time
  @time
end

#unit_of_work_idObject

Returns the value of attribute unit_of_work_id.



5
6
7
# File 'lib/lumberjack/log_entry.rb', line 5

def unit_of_work_id
  @unit_of_work_id
end

Instance Method Details

#inspectObject



32
33
34
# File 'lib/lumberjack/log_entry.rb', line 32

def inspect
  to_s
end

#severity_labelObject



18
19
20
# File 'lib/lumberjack/log_entry.rb', line 18

def severity_label
  Severity.level_to_label(severity)
end

#to_sObject



22
23
24
25
26
27
28
29
30
# File 'lib/lumberjack/log_entry.rb', line 22

def to_s
  buf = "[#{time.strftime(TIME_FORMAT)}.#{(time.usec / 1000.0).round.to_s.rjust(3, '0')} #{severity_label} #{progname}(#{pid})"
  if unit_of_work_id
    buf << " #"
    buf << unit_of_work_id
  end
  buf << "] "
  buf << message
end