Class: Timber::Events::Custom
- Inherits:
-
Timber::Event
- Object
- Timber::Event
- Timber::Events::Custom
- Defined in:
- lib/timber/events/custom.rb
Overview
Allows for custom events that aren’t covered elsewhere.
Custom events can be used to encode information about events that are central to your line of business like receiving credit card payments, saving a draft of a post, or changing a user’s password.
For examples of logging custom events see Logger.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #as_json(_options = {}) ⇒ Object
-
#initialize(attributes) ⇒ Custom
constructor
Instantiates a new custom event that can be logged.
- #to_hash ⇒ Object (also: #to_h)
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Custom
Instantiates a new custom event that can be logged. See Logger for examples on logging custom events.
22 23 24 25 26 |
# File 'lib/timber/events/custom.rb', line 22 def initialize(attributes) @type = attributes[:type] || raise(ArgumentError.new(":type is required")) @message = attributes[:message] || raise(ArgumentError.new(":message is required")) @data = attributes[:data] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/timber/events/custom.rb', line 11 def data @data end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/timber/events/custom.rb', line 11 def @message end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/timber/events/custom.rb', line 11 def type @type end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
33 34 35 |
# File 'lib/timber/events/custom.rb', line 33 def as_json( = {}) {:custom => to_hash} end |
#to_hash ⇒ Object Also known as: to_h
28 29 30 |
# File 'lib/timber/events/custom.rb', line 28 def to_hash {type => data} end |
#to_json(options = {}) ⇒ Object
37 38 39 |
# File 'lib/timber/events/custom.rb', line 37 def to_json( = {}) as_json().to_json() end |