Class: Timber::LogEntry
- Inherits:
-
Object
- Object
- Timber::LogEntry
- Defined in:
- lib/timber/log_entry.rb
Overview
Represents a new log entry into the log. This is an intermediary class between ‘Logger` and the log device that you set it up with.
Constant Summary collapse
- DT_PRECISION =
:nodoc:
6.freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#progname ⇒ Object
readonly
Returns the value of attribute progname.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(level, time, progname, message, context, event) ⇒ LogEntry
constructor
Creates a log entry suitable to be sent to the Timber API.
- #to_json(options = {}) ⇒ Object
- #to_msgpack(*args) ⇒ Object
Constructor Details
#initialize(level, time, progname, message, context, event) ⇒ LogEntry
Creates a log entry suitable to be sent to the Timber API.
16 17 18 19 20 21 22 23 |
# File 'lib/timber/log_entry.rb', line 16 def initialize(level, time, progname, , context, event) @level = level @time = time.utc @progname = progname @message = @context = context @event = event end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def context @context end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def event @event end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def @message end |
#progname ⇒ Object (readonly)
Returns the value of attribute progname.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def progname @progname end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
7 8 9 |
# File 'lib/timber/log_entry.rb', line 7 def time @time end |
Instance Method Details
#as_json(options = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/timber/log_entry.rb', line 25 def as_json( = {}) ||= {} hash = {level: level, dt: formatted_dt, message: } if !event.nil? hash[:event] = event end if !context.nil? && context.length > 0 hash[:context] = context end if [:only] hash.select do |key, _value| [:only].include?(key) end elsif [:except] hash.select do |key, _value| ![:except].include?(key) end else hash end end |
#to_json(options = {}) ⇒ Object
50 51 52 |
# File 'lib/timber/log_entry.rb', line 50 def to_json( = {}) as_json().to_json end |
#to_msgpack(*args) ⇒ Object
54 55 56 |
# File 'lib/timber/log_entry.rb', line 54 def to_msgpack(*args) as_json.to_msgpack(*args) end |