Class: Lumberjack::LogEntry
- Inherits:
-
Object
- Object
- Lumberjack::LogEntry
- 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
-
#message ⇒ Object
Returns the value of attribute message.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#progname ⇒ Object
Returns the value of attribute progname.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(time, severity, message, progname, pid, tags) ⇒ LogEntry
constructor
Create a new log entry.
- #inspect ⇒ Object
- #severity_label ⇒ Object
-
#tag(name) ⇒ Object
Return the tag with the specified name.
- #to_s ⇒ Object
-
#unit_of_work_id ⇒ Object
Deprecated - backward compatibility with 1.0 API.
-
#unit_of_work_id=(value) ⇒ Object
Deprecated - backward compatibility with 1.0 API.
Constructor Details
#initialize(time, severity, message, progname, pid, tags) ⇒ LogEntry
Create a new log entry.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/lumberjack/log_entry.rb', line 21 def initialize(time, severity, , progname, pid, ) @time = time @severity = (severity.is_a?(Integer) ? severity : Severity.label_to_level(severity)) @message = @progname = progname @pid = pid # backward compatibility with 1.0 API where the last argument was the unit of work id @tags = if .nil? || .is_a?(Hash) else {UNIT_OF_WORK_ID => } end end |
Instance Attribute Details
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def @message end |
#pid ⇒ Object
Returns the value of attribute pid.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def pid @pid end |
#progname ⇒ Object
Returns the value of attribute progname.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def progname @progname end |
#severity ⇒ Object
Returns the value of attribute severity.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def severity @severity end |
#tags ⇒ Object
Returns the value of attribute tags.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def @tags end |
#time ⇒ Object
Returns the value of attribute time.
7 8 9 |
# File 'lib/lumberjack/log_entry.rb', line 7 def time @time end |
Instance Method Details
#inspect ⇒ Object
43 44 45 |
# File 'lib/lumberjack/log_entry.rb', line 43 def inspect to_s end |
#severity_label ⇒ Object
35 36 37 |
# File 'lib/lumberjack/log_entry.rb', line 35 def severity_label Severity.level_to_label(severity) end |
#tag(name) ⇒ Object
Return the tag with the specified name.
62 63 64 |
# File 'lib/lumberjack/log_entry.rb', line 62 def tag(name) [name.to_s] if end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/lumberjack/log_entry.rb', line 39 def to_s "[#{time.strftime(TIME_FORMAT)}.#{(time.usec / 1000.0).round.to_s.rjust(3, "0")} #{severity_label} #{progname}(#{pid})#{}] #{}" end |
#unit_of_work_id ⇒ Object
Deprecated - backward compatibility with 1.0 API
48 49 50 |
# File 'lib/lumberjack/log_entry.rb', line 48 def unit_of_work_id [UNIT_OF_WORK_ID] if end |
#unit_of_work_id=(value) ⇒ Object
Deprecated - backward compatibility with 1.0 API
53 54 55 56 57 58 59 |
# File 'lib/lumberjack/log_entry.rb', line 53 def unit_of_work_id=(value) if [UNIT_OF_WORK_ID] = value else @tags = {UNIT_OF_WORK_ID => value} end end |