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
- SCHEMA =
"https://raw.githubusercontent.com/timberio/log-event-json-schema/1.2.4/schema.json".freeze
Instance Attribute Summary collapse
-
#context_snapshot ⇒ Object
readonly
Returns the value of attribute context_snapshot.
-
#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.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#time_ms ⇒ Object
readonly
Returns the value of attribute time_ms.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(level, time, progname, message, context_snapshot, event, options = {}) ⇒ 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_snapshot, event, options = {}) ⇒ LogEntry
Creates a log entry suitable to be sent to the Timber API.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/timber/log_entry.rb', line 20 def initialize(level, time, progname, , context_snapshot, event, = {}) @level = level @time = time.utc @progname = progname = = [:tags] @time_ms = [:time_ms] context_snapshot = {} if context_snapshot.nil? system_context = Contexts::System.new(pid: Process.pid) context_snapshot[system_context.keyspace] = system_context.as_json @context_snapshot = context_snapshot @event = event end |
Instance Attribute Details
#context_snapshot ⇒ Object (readonly)
Returns the value of attribute context_snapshot.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def context_snapshot @context_snapshot end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def event @event end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def end |
#progname ⇒ Object (readonly)
Returns the value of attribute progname.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def progname @progname end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def time @time end |
#time_ms ⇒ Object (readonly)
Returns the value of attribute time_ms.
8 9 10 |
# File 'lib/timber/log_entry.rb', line 8 def time_ms @time_ms end |
Instance Method Details
#as_json(options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/timber/log_entry.rb', line 36 def as_json( = {}) ||= {} hash = {:level => level, :dt => formatted_dt, :message => , :tags => , :time_ms => time_ms} if !event.nil? hash[:event] = event end if !context_snapshot.nil? && context_snapshot.length > 0 hash[:context] = context_snapshot end hash[:"$schema"] = SCHEMA hash = 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 Util::Hash.compact(hash) end |
#to_json(options = {}) ⇒ Object
66 67 68 |
# File 'lib/timber/log_entry.rb', line 66 def to_json( = {}) as_json().to_json end |
#to_msgpack(*args) ⇒ Object
70 71 72 |
# File 'lib/timber/log_entry.rb', line 70 def to_msgpack(*args) as_json.to_msgpack(*args) end |