Class: Faulty::Events::LogListener

Inherits:
Object
  • Object
show all
Defined in:
lib/faulty/events/log_listener.rb

Overview

A default listener that logs Faulty events

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger = nil) ⇒ LogListener

Returns a new instance of LogListener.

Parameters:

  • logger (defaults to: nil)

    A logger similar to stdlib Logger. Uses the Rails logger by default if available, otherwise it creates a new Logger to stderr.


12
13
14
15
# File 'lib/faulty/events/log_listener.rb', line 12

def initialize(logger = nil)
  logger ||= defined?(Rails) ? Rails.logger : ::Logger.new($stderr)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger


7
8
9
# File 'lib/faulty/events/log_listener.rb', line 7

def logger
  @logger
end

Instance Method Details

#handle(event, payload) ⇒ void

This method returns an undefined value.

Handle an event raised by Faulty

Parameters:

  • event (Symbol)

    The event name. Will be a member of EVENTS.

  • payload (Hash)

    A hash with keys based on the event type


18
19
20
21
22
# File 'lib/faulty/events/log_listener.rb', line 18

def handle(event, payload)
  return unless EVENTS.include?(event)

  send(event, payload) if respond_to?(event, true)
end