Class: Logr::Entry
- Inherits:
-
Object
- Object
- Logr::Entry
- Defined in:
- lib/logr/entry.rb
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#metrics ⇒ Object
readonly
Returns the value of attribute metrics.
Instance Method Summary collapse
- #debug(message = nil, &block) ⇒ Object
- #error(message = nil, &block) ⇒ Object
- #event(name = nil, tags = {}) ⇒ Object
- #fatal(message = nil, &block) ⇒ Object
- #info(message = nil, &block) ⇒ Object
-
#initialize(logger, event = nil, metrics = [], message = nil) ⇒ Entry
constructor
A new instance of Entry.
- #metric(name, value, type: "counter") ⇒ Object
- #monitored(title, text) ⇒ Object
- #to_hash ⇒ Object
- #warn(message = nil, &block) ⇒ Object
- #with(tags = {}) ⇒ Object
Constructor Details
#initialize(logger, event = nil, metrics = [], message = nil) ⇒ Entry
Returns a new instance of Entry.
9 10 11 12 13 14 |
# File 'lib/logr/entry.rb', line 9 def initialize(logger, event=nil, metrics=[], =nil) @logger = logger @event = event @metrics = metrics @message = end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/logr/entry.rb', line 7 def @message end |
#metrics ⇒ Object (readonly)
Returns the value of attribute metrics.
7 8 9 |
# File 'lib/logr/entry.rb', line 7 def metrics @metrics end |
Instance Method Details
#debug(message = nil, &block) ⇒ Object
44 45 46 |
# File 'lib/logr/entry.rb', line 44 def debug(=nil, &block) add(:debug, , &block) end |
#error(message = nil, &block) ⇒ Object
56 57 58 |
# File 'lib/logr/entry.rb', line 56 def error(=nil, &block) add(:error, , &block) end |
#event(name = nil, tags = {}) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/logr/entry.rb', line 16 def event(name=nil, ={}) if name.nil? @event else Entry.new(@logger, Event.new(name, ), @metrics) end end |
#fatal(message = nil, &block) ⇒ Object
60 61 62 |
# File 'lib/logr/entry.rb', line 60 def fatal(=nil, &block) add(:fatal, , &block) end |
#info(message = nil, &block) ⇒ Object
48 49 50 |
# File 'lib/logr/entry.rb', line 48 def info(=nil, &block) add(:info, , &block) end |
#metric(name, value, type: "counter") ⇒ Object
31 32 33 34 |
# File 'lib/logr/entry.rb', line 31 def metric(name, value, type: "counter") metric = Metric.new(name, value, type) Entry.new(@logger, @event, @metrics + [metric]) end |
#monitored(title, text) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/logr/entry.rb', line 36 def monitored(title, text) if @event.nil? raise 'No event to monitor. Please call #event first.' end event = @event.with(monitored: true, title: title, text: text) Entry.new(@logger, event, @metrics) end |
#to_hash ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/logr/entry.rb', line 64 def to_hash result = {} result[:event] = @event.to_hash if @event result[:metrics] = @metrics.map(&:to_hash) if @metrics.any? result[:message] = @message if @message result end |
#warn(message = nil, &block) ⇒ Object
52 53 54 |
# File 'lib/logr/entry.rb', line 52 def warn(=nil, &block) add(:warn, , &block) end |