Class: Chook::HandledEventLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/chook/event/handled_event_logger.rb

Overview

a simple object embedded in a Handled Event that allows a standardize way to note event-related log entries with the event object_id.

Every Handled Event has one of these instances exposed in it’s #logger attribute, and usable from within ‘internal’ handlers

Here’s an example.

Say you have a ComputerSmartGroupMembershipChanged event

calling ‘event.logger.info “foobar”` will generate the log message:

Event 1234567: foobar

Instance Method Summary collapse

Constructor Details

#initialize(event) ⇒ HandledEventLogger

Returns a new instance of HandledEventLogger.



45
46
47
# File 'lib/chook/event/handled_event_logger.rb', line 45

def initialize(event)
  @event = event
end

Instance Method Details

#debug(msg) ⇒ Object



53
54
55
# File 'lib/chook/event/handled_event_logger.rb', line 53

def debug(msg)
  Chook::Server::Log.logger.debug event_message(msg)
end

#error(msg) ⇒ Object



65
66
67
# File 'lib/chook/event/handled_event_logger.rb', line 65

def error(msg)
  Chook::Server::Log.logger.error event_message(msg)
end

#event_message(msg) ⇒ Object



49
50
51
# File 'lib/chook/event/handled_event_logger.rb', line 49

def event_message(msg)
  "Event #{@event.id}: #{msg}"
end

#fatal(msg) ⇒ Object



69
70
71
# File 'lib/chook/event/handled_event_logger.rb', line 69

def fatal(msg)
  Chook::Server::Log.logger.fatal event_message(msg)
end

#info(msg) ⇒ Object



57
58
59
# File 'lib/chook/event/handled_event_logger.rb', line 57

def info(msg)
  Chook::Server::Log.logger.info event_message(msg)
end

#log_exception(exception) ⇒ Object

log an exception - multiple log lines the first being the error message the rest being indented backtrace



79
80
81
82
# File 'lib/chook/event/handled_event_logger.rb', line 79

def log_exception(exception)
  error "#{exception.class}: #{exception}"
  exception.backtrace.each { |l| error "..#{l}" }
end

#unknown(msg) ⇒ Object



73
74
75
# File 'lib/chook/event/handled_event_logger.rb', line 73

def unknown(msg)
  Chook::Server::Log.logger.unknown event_message(msg)
end

#warn(msg) ⇒ Object



61
62
63
# File 'lib/chook/event/handled_event_logger.rb', line 61

def warn(msg)
  Chook::Server::Log.logger.warn event_message(msg)
end