Sha256: 968661faabb7863c7814ed354ae2b0f5ce4a9230551a7f175e9b566bab954c0d

Contents?: true

Size: 1.09 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
celluloid-essentials-0.20.5 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.2.1 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.2 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.1.1 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.1 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre17 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre16 lib/celluloid/logging/incident_reporter.rb
celluloid-essentials-0.20.0.pre15 lib/celluloid/logging/incident_reporter.rb