Class: EventLogger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/event_logger.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventLogger

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

#loggerObject

Returns the value of attribute logger.



9
10
11
# File 'lib/event_logger.rb', line 9

def logger
  @logger
end

#mappingObject

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_idObject



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