Class: Celluloid::IncidentReporter

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Notifications
Defined in:
lib/celluloid/logging/incident_reporter.rb

Overview

Subscribes to log incident topics to report on them.

Defined Under Namespace

Classes: Formatter

Constant Summary

Constants included from Celluloid

BARE_OBJECT_WARNING_MESSAGE, DeadActorError, Error, LINKING_TIMEOUT, NotActorError, OWNER_IVAR, TIMER_QUANTUM, TimeoutError, VERSION

Instance Method Summary collapse

Methods included from Notifications

notifier, #publish, #subscribe, #unsubscribe

Methods included from Celluloid

#abort, actor?, #after, #async, boot, #call_chain_id, cores, #current_actor, #defer, detect_recursion, #every, exception_handler, #exclusive, #exclusive?, #future, included, init, #link, #linked_to?, #links, mailbox, #monitor, #monitoring?, #receive, register_shutdown, running?, shutdown, #signal, #sleep, stack_dump, start, suspend, #tasks, #terminate, #timeout, #unlink, #unmonitor, uuid, version, #wait

Constructor Details

#initialize(*args) ⇒ IncidentReporter

Returns a new instance of IncidentReporter.


15
16
17
18
19
20
# File 'lib/celluloid/logging/incident_reporter.rb', line 15

def initialize(*args)
  subscribe(/log\.incident/, :report)
  @logger = ::Logger.new(*args)
  @logger.formatter = Formatter.new
  @silenced = false
end

Instance Method Details

#report(topic, incident) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/celluloid/logging/incident_reporter.rb', line 22

def report(topic, incident)
  return if @silenced

  header = "INCIDENT"
  header << " AT #{incident.triggering_event.time}" if incident.triggering_event
  @logger << header
  @logger << "\n"
  @logger << "====================\n"
  incident.events.each do |event|
    @logger.add(event.severity, event, event.progname)
  end
  @logger << "====================\n"
end

#silenceObject


36
37
38
# File 'lib/celluloid/logging/incident_reporter.rb', line 36

def silence
  @silenced = true
end

#silenced?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/celluloid/logging/incident_reporter.rb', line 44

def silenced?
  @silenced
end

#unsilenceObject


40
41
42
# File 'lib/celluloid/logging/incident_reporter.rb', line 40

def unsilence
  @silenced = false
end