Class: Cogger::Entry
- Inherits:
-
Data
- Object
- Data
- Cogger::Entry
- Defined in:
- lib/cogger/entry.rb
Overview
Defines a log entry which can be formatted for output.
Instance Attribute Summary collapse
-
#at ⇒ Object
readonly
Returns the value of attribute at.
-
#datetime_format ⇒ Object
readonly
Returns the value of attribute datetime_format.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(id: Program.call, level: "INFO", at: ::Time.now, message: nil, tags: Core::EMPTY_ARRAY, datetime_format: DATETIME_FORMAT, payload: Core::EMPTY_HASH) ⇒ Entry
constructor
A new instance of Entry.
- #tagged(tagger: Tag) ⇒ Object
- #tagged_attributes(tagger: Tag) ⇒ Object
Constructor Details
#initialize(id: Program.call, level: "INFO", at: ::Time.now, message: nil, tags: Core::EMPTY_ARRAY, datetime_format: DATETIME_FORMAT, payload: Core::EMPTY_HASH) ⇒ Entry
Returns a new instance of Entry.
47 48 49 50 51 52 53 54 55 |
# File 'lib/cogger/entry.rb', line 47 def initialize id: Program.call, level: "INFO", at: ::Time.now, message: nil, tags: Core::EMPTY_ARRAY, datetime_format: DATETIME_FORMAT, payload: Core::EMPTY_HASH super end |
Instance Attribute Details
#at ⇒ Object (readonly)
Returns the value of attribute at
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def at @at end |
#datetime_format ⇒ Object (readonly)
Returns the value of attribute datetime_format
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def datetime_format @datetime_format end |
#id ⇒ Object (readonly)
Returns the value of attribute id
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def id @id end |
#level ⇒ Object (readonly)
Returns the value of attribute level
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def level @level end |
#message ⇒ Object (readonly)
Returns the value of attribute message
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def @message end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def payload @payload end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags
7 8 9 |
# File 'lib/cogger/entry.rb', line 7 def @tags end |
Class Method Details
.for(message = nil, **payload) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/cogger/entry.rb', line 8 def self.for( = nil, **payload, &) content = block_given? ? yield : new id: payload.delete(:id) || Program.call, level: (payload.delete(:level) || "INFO").upcase, at: payload.delete(:at) || ::Time.now, message: sanitize!(content, payload), tags: Array(payload.delete(:tags)), datetime_format: payload.delete(:datetime_format) || DATETIME_FORMAT, payload: end |
.for_crash(message, error, id:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cogger/entry.rb', line 20 def self.for_crash , error, id: new id:, level: "FATAL", message:, payload: { error_message: error., error_class: error.class, backtrace: error.backtrace } end |
Instance Method Details
#attributes ⇒ Object
57 |
# File 'lib/cogger/entry.rb', line 57 def attributes = {id:, level:, at:, message:, **payload} |
#tagged(tagger: Tag) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/cogger/entry.rb', line 67 def tagged tagger: Tag attributes.tap do |pairs| = tagger.for(*) pairs[:message] = "#{} #{pairs[:message]}" unless .empty? end end |
#tagged_attributes(tagger: Tag) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/cogger/entry.rb', line 59 def tagged_attributes tagger: Tag = tagger.for(*) return attributes if .empty? {id:, level:, at:, message:, **.to_h, **payload} end |