Class: EventLogger
Overview
Event logger based on: blog.logentries.com/2015/07/ditch-the-debugger-and-use-log-analysis-instead/
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#mapping ⇒ Object
Returns the value of attribute mapping.
Class Method Summary collapse
Instance Method Summary collapse
- #create_correlation_id ⇒ Object
-
#initialize ⇒ EventLogger
constructor
A new instance of EventLogger.
- #log(type, details = {}) ⇒ Object
Constructor Details
#initialize ⇒ EventLogger
Returns a new instance of EventLogger.
14 15 16 17 |
# File 'lib/event_logger.rb', line 14 def initialize @logger = Logger.new(STDOUT) @mapping = nil end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
9 10 11 |
# File 'lib/event_logger.rb', line 9 def logger @logger end |
#mapping ⇒ Object
Returns the value of attribute mapping.
10 11 12 |
# File 'lib/event_logger.rb', line 10 def mapping @mapping end |
Class Method Details
.log(*args) ⇒ Object
19 20 21 |
# File 'lib/event_logger.rb', line 19 def self.log(*args) instance.log(*args) end |
Instance Method Details
#create_correlation_id ⇒ Object
34 35 36 |
# File 'lib/event_logger.rb', line 34 def create_correlation_id UUIDTools::UUID.random_create.to_s end |
#log(type, details = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/event_logger.rb', line 23 def log(type, details = {}) severity = if details.key?(:severity) details.delete(:severity) elsif @mapping && @mapping.key?(details[:name]) @mapping[details[:name]][:severity] else 'info' end @logger.send(severity, format_log_entry(details_for(type, details))) end |