Sha256: c18df65dc400b0b96166ab59b80e5ca3314c099fac85e886811ad11e84b5f4e8

Contents?: true

Size: 1.09 KB

Versions: 34

Compression:

Stored size: 1.09 KB

Contents

require 'logger'
module Celluloid
  # Subscribes to log incident topics to report on them.
  class IncidentReporter
    include Celluloid
    include Celluloid::Notifications

    # get the time from the event
    class Formatter < ::Logger::Formatter
      def call(severity, time, progname, msg)
        super(severity, msg.time, progname, msg.message)
      end
    end

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

    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

    def silence
      @silenced = true
    end

    def unsilence
      @silenced = false
    end

    def silenced?
      @silenced
    end
  end
end

Version data entries

34 entries across 32 versions & 7 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/celluloid-0.16.0/lib/celluloid/logging/incident_reporter.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/celluloid-0.16.0/lib/celluloid/logging/incident_reporter.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/logging/incident_reporter.rb
scoot-0.0.4 .bundle/gems/ruby/2.2.0/gems/celluloid-0.16.0/lib/celluloid/logging/incident_reporter.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/celluloid-0.16.0/lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre14 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre13 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre12 lib/celluloid/logging/incident_reporter.rb
celluloid-0.16.0 lib/celluloid/logging/incident_reporter.rb
celluloid-0.16.0.pre3 lib/celluloid/logging/incident_reporter.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/gems/celluloid-0.15.2/lib/celluloid/logging/incident_reporter.rb
celluloid-0.16.0.pre2 lib/celluloid/logging/incident_reporter.rb
celluloid-0.16.0.pre lib/celluloid/logging/incident_reporter.rb
celluloid-0.15.2 lib/celluloid/logging/incident_reporter.rb
celluloid-0.15.1 lib/celluloid/logging/incident_reporter.rb
celluloid-0.15.0 lib/celluloid/logging/incident_reporter.rb
celluloid-0.15.0.pre2 lib/celluloid/logging/incident_reporter.rb
celluloid-0.15.0.pre lib/celluloid/logging/incident_reporter.rb
celluloid-0.14.1 lib/celluloid/logging/incident_reporter.rb
celluloid-0.14.1.pre lib/celluloid/logging/incident_reporter.rb