Class: Collective::Utilities::LogObserver

Inherits:
ObserverBase show all
Includes:
Log
Defined in:
lib/collective/utilities/log_observer.rb

Overview

Wrapps a callable and issues feedback.

- Started
- Hearbeat
- Error
- Stopped

Instance Attribute Summary

Attributes inherited from ObserverBase

#subject

Instance Method Summary collapse

Methods included from Log

#format_for_logging, #log, #logger, #logger=

Methods inherited from ObserverBase

camelize, #focus, #notify, resolve

Constructor Details

#initialize(filename = nil) ⇒ LogObserver

Returns a new instance of LogObserver.



17
18
19
20
21
# File 'lib/collective/utilities/log_observer.rb', line 17

def initialize( filename = nil )
  if filename then
    self.logger = File.open(filename,"a") # append or create, write only
  end
end

Instance Method Details

#job_error(x) ⇒ Object



31
32
33
34
# File 'lib/collective/utilities/log_observer.rb', line 31

def job_error(x)
  log "Warning: #{subject} experienced a job failure due to an error:#{x.inspect}"
  log x.backtrace
end

#worker_heartbeat(*args) ⇒ Object



27
28
29
# File 'lib/collective/utilities/log_observer.rb', line 27

def worker_heartbeat( *args )
  log "#{subject} is still alive"
end

#worker_started(*args) ⇒ Object



23
24
25
# File 'lib/collective/utilities/log_observer.rb', line 23

def worker_started( *args )
  log "#{subject} has started"
end

#worker_stopped(*args) ⇒ Object



36
37
38
# File 'lib/collective/utilities/log_observer.rb', line 36

def worker_stopped( *args )
  log "#{subject} has stopped"
end