class EventLogger
Event logger based on: blog.logentries.com/2015/07/ditch-the-debugger-and-use-log-analysis-instead/
Outputs log entries to an IO stream, one JSON hash per entry.
Adds `generated_at` and `severity` fields to the hash with the current timestamp in milliseconds and the entry severity.
Outputs log entries to a Logger object, one JSON hash per entry.
Can be used with the Ruby Logger or another that responds to per-severity methods.
Attributes
config[R]
mapping[RW]
Public Class Methods
log(*args)
click to toggle source
# File lib/event_logger.rb, line 19 def self.log(*args) instance.log(*args) end
new()
click to toggle source
# File lib/event_logger.rb, line 14 def initialize @config = Config.new @mapping = nil end
Public Instance Methods
create_correlation_id()
click to toggle source
# File lib/event_logger.rb, line 37 def create_correlation_id SecureRandom.uuid end
log(type, details = {})
click to toggle source
# 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.to_sym config.logger_instance.write severity, details_for(type, details) nil end
Private Instance Methods
details_for(type, details)
click to toggle source
# File lib/event_logger.rb, line 43 def details_for(type, details) { type: type }.merge(details) end