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"
UNIT_OF_WORK_ID =
"unit_of_work_id"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LogEntry.



13
14
15
16
17
18
19
20
21
22
23
24
25
# 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
  if tags.nil? || tags.is_a?(Hash)
    @tags = tags
  else
    @tags = { UNIT_OF_WORK_ID => tags }
  end
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def message
  @message
end

#pidObject

Returns the value of attribute pid.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def pid
  @pid
end

#prognameObject

Returns the value of attribute progname.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def progname
  @progname
end

#severityObject

Returns the value of attribute severity.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def severity
  @severity
end

#tagsObject

Returns the value of attribute tags.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def tags
  @tags
end

#timeObject

Returns the value of attribute time.



7
8
9
# File 'lib/lumberjack/log_entry.rb', line 7

def time
  @time
end

Instance Method Details

#inspectObject



35
36
37
# File 'lib/lumberjack/log_entry.rb', line 35

def inspect
  to_s
end

#severity_labelObject



27
28
29
# File 'lib/lumberjack/log_entry.rb', line 27

def severity_label
  Severity.level_to_label(severity)
end

#tag(name) ⇒ Object

Return the tag with the specified name.



54
55
56
# File 'lib/lumberjack/log_entry.rb', line 54

def tag(name)
  tags[name.to_s] if tags
end

#to_sObject



31
32
33
# 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_idObject

Deprecated - backward compatibility with 1.0 API



40
41
42
# 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) ⇒ Object

Deprecated - backward compatibility with 1.0 API



45
46
47
48
49
50
51
# 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