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

CPUCounter, Links, Logger, Properties, Registry, StackDump, ThreadHandle, UUID

Instance Method Summary collapse

Methods included from Notifications

notifier, publish, #subscribe, #unsubscribe

Methods included from Celluloid

publish

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