Class: Semlogr::Events::LogEvent
- Inherits:
-
Object
- Object
- Semlogr::Events::LogEvent
- Defined in:
- lib/semlogr/events/log_event.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
Instance Method Summary collapse
- #add_property(properties) ⇒ Object
- #add_property_if_absent(properties) ⇒ Object
- #get_property(name) ⇒ Object
-
#initialize(severity, template, error: nil, **properties) ⇒ LogEvent
constructor
A new instance of LogEvent.
- #render(output) ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(severity, template, error: nil, **properties) ⇒ LogEvent
Returns a new instance of LogEvent.
15 16 17 18 19 20 21 |
# File 'lib/semlogr/events/log_event.rb', line 15 def initialize(severity, template, error: nil, **properties) @timestamp = Time.now.utc @severity = severity @template = template @error = error @properties = properties end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
11 12 13 |
# File 'lib/semlogr/events/log_event.rb', line 11 def error @error end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
12 13 14 |
# File 'lib/semlogr/events/log_event.rb', line 12 def properties @properties end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
9 10 11 |
# File 'lib/semlogr/events/log_event.rb', line 9 def severity @severity end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
10 11 12 |
# File 'lib/semlogr/events/log_event.rb', line 10 def template @template end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
13 14 15 |
# File 'lib/semlogr/events/log_event.rb', line 13 def @timestamp end |
Class Method Details
Instance Method Details
#add_property(properties) ⇒ Object
33 34 35 |
# File 'lib/semlogr/events/log_event.rb', line 33 def add_property(properties) @properties.merge!(properties) end |
#add_property_if_absent(properties) ⇒ Object
37 38 39 |
# File 'lib/semlogr/events/log_event.rb', line 37 def add_property_if_absent(properties) @properties.merge!(properties) { |_, old, _| old } end |
#get_property(name) ⇒ Object
29 30 31 |
# File 'lib/semlogr/events/log_event.rb', line 29 def get_property(name) @properties[name] end |
#render(output) ⇒ Object
41 42 43 |
# File 'lib/semlogr/events/log_event.rb', line 41 def render(output) @template.render(output, @properties) end |
#to_s ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/semlogr/events/log_event.rb', line 49 def to_s output = +'' render(output) output end |
#type ⇒ Object
45 46 47 |
# File 'lib/semlogr/events/log_event.rb', line 45 def type @type ||= Digest::XXH32.hexdigest(@template.text) end |