Class: Celluloid::IncidentLogger

### Home Classes Methods

### In Files

- lib/celluloid/logging/incident_logger.rb

### Parent

Object

### Namespace

- MODULE Celluloid::IncidentLogger::Severity

### Methods

- ::new
- #add
- #clear
- #create_incident
- #debug
- #error
- #fatal
- #flush
- #incident_topic
- #info
- #log
- #trace
- #unknown
- #warn

### Included Modules

- Celluloid::IncidentLogger::Severity

### Class/Module Index

Quicksearch

- Celluloid
- Celluloid::AbortError
- Celluloid::AbstractProxy
- Celluloid::Actor
- Celluloid::Actor::Sleeper
- Celluloid::ActorProxy
- Celluloid::ActorSystem
- Celluloid::AsyncCall
- Celluloid::AsyncProxy
- Celluloid::BlockCall
- Celluloid::BlockProxy
- Celluloid::BlockResponse
- Celluloid::CPUCounter
- Celluloid::Call
- Celluloid::CallChain
- Celluloid::Cell
- Celluloid::Cell::ExitHandler
- Celluloid::CellProxy
- Celluloid::ClassMethods
- Celluloid::Condition
- Celluloid::Condition::Waiter
- Celluloid::ConditionError
- Celluloid::DeadTaskError
- Celluloid::ErrorResponse
- Celluloid::EventedMailbox
- Celluloid::ExitEvent
- Celluloid::FSM
- Celluloid::FSM::ClassMethods
- Celluloid::FSM::State
- Celluloid::FSM::UnattachedError
- Celluloid::FiberStackError
- Celluloid::Future
- Celluloid::Future::Result
- Celluloid::FutureProxy
- Celluloid::Handler
- Celluloid::Handlers
- Celluloid::Incident
- Celluloid::IncidentLogger
- Celluloid::IncidentLogger::Severity
- Celluloid::IncidentReporter
- Celluloid::IncidentReporter::Formatter
- Celluloid::InstanceMethods
- Celluloid::InternalPool
- Celluloid::LinkingRequest
- Celluloid::LinkingResponse
- Celluloid::Links
- Celluloid::LogEvent
- Celluloid::Logger
- Celluloid::Logger::WithBacktrace
- Celluloid::Mailbox
- Celluloid::MailboxDead
- Celluloid::MailboxShutdown
- Celluloid::Method
- Celluloid::NamingRequest
- Celluloid::NotTaskError
- Celluloid::Notifications
- Celluloid::Notifications::Fanout
- Celluloid::Notifications::Subscriber
- Celluloid::PoolManager
- Celluloid::Probe
- Celluloid::Properties
- Celluloid::Receiver
- Celluloid::Receivers
- Celluloid::Registry
- Celluloid::Response
- Celluloid::ResumableError
- Celluloid::RingBuffer
- Celluloid::SignalConditionRequest
- Celluloid::Signals
- Celluloid::StackDump
- Celluloid::StackDump::ActorState
- Celluloid::StackDump::CellState
- Celluloid::StackDump::DisplayBacktrace
- Celluloid::StackDump::TaskState
- Celluloid::StackDump::ThreadState
- Celluloid::SuccessResponse
- Celluloid::SupervisionGroup
- Celluloid::SupervisionGroup::Member
- Celluloid::Supervisor
- Celluloid::SyncCall
- Celluloid::SyncProxy
- Celluloid::SystemEvent
- Celluloid::Task
- Celluloid::Task::TerminatedError
- Celluloid::Task::TimeoutError
- Celluloid::TaskFiber
- Celluloid::TaskSet
- Celluloid::TaskThread
- Celluloid::TerminationRequest
- Celluloid::Thread
- Celluloid::ThreadHandle
- Celluloid::UUID
- org
- org::jruby
- org::jruby::ext
- org::jruby::ext::fiber
- org::jruby::ext::fiber::ThreadFiber
- Bar
- Baz
- Blocker
- ExampleActorClass
- ExampleCrash
- ExampleMailbox
- ExampleProxy
- ExampleTask
- Fiber
- Foo
- MockActor
- Object
- Thread

No matching classes.

# Celluloid::IncidentLogger

A logger that holds all messages in circular buffers, then flushes the buffers when an event occurs at a configurable severity threshold.

Unlike ruby's Logger, this class only supports a single progname.

### Attributes

buffers[RW]
level[RW]

The logging level. Messages below this severity will not be logged at all.

progname[RW]

The progname (facility) for this instance.

sizelimit[RW]

The buffer size limit. Each log level will retain this number of messages at maximum.

threshold[RW]

The incident threshold. Messages at or above this severity will generate an incident and be published to incident reporters.

### Public Class Methods

new(progname=nil, options={}) click to toggle source

Create a new IncidentLogger.

    # File lib/celluloid/logging/incident_logger.rb, line 45
    def initialize(progname=nil, options={})
      @progname = progname || "default"
      @level = options[:level] || DEBUG
      @threshold = options[:threshold] || ERROR
      @sizelimit = options[:sizelimit] || 100

      @buffer_mutex = Mutex.new
      @buffers = Hash.new do |progname_hash, _progname|
        @buffer_mutex.synchronize do
          progname_hash[_progname] = Hash.new do |severity_hash, severity|
            severity_hash[severity] = RingBuffer.new(@sizelimit)
          end
        end
      end

      # When the IncidentLogger itself encounters an error, it falls back to logging to stderr
      @fallback_logger = ::Logger.new(STDERR)
      @fallback_logger.progname = "FALLBACK"
    end

### Public Instance Methods

add(severity, message=nil, progname=nil, &block) click to toggle source

add an event.

    # File lib/celluloid/logging/incident_logger.rb, line 66
    def add(severity, message=nil, progname=nil, &block)
      progname ||= @progname
      severity ||= UNKNOWN

      if severity < @level
        return event.id
      end

      if message.nil? && !block_given?
        message = progname
        progname = @progname
      end

      event = LogEvent.new(severity, message, progname, &block)

      @buffers[progname][severity] << event

      if severity >= @threshold
        begin
          Celluloid::Notifications.notifier.async.publish(incident_topic, create_incident(event))
        rescue => ex
          @fallback_logger.error(ex)
        end
      end
      event.id
    end

Also aliased as: log
clear() click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 115
    def clear
      @buffer_mutex.synchronize do
        @buffers.each { |buffer| buffer.clear }
      end
    end

create_incident(event=nil) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 121
    def create_incident(event=nil)
      Incident.new(flush, event)
    end

debug(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 96
    def debug   (progname=nil, &block); add(DEBUG,   nil, progname, &block); end

error(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 99
    def error   (progname=nil, &block); add(ERROR,   nil, progname, &block); end

fatal(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 100
    def fatal   (progname=nil, &block); add(FATAL,   nil, progname, &block); end

flush() click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 103
    def flush
      messages = []
      @buffer_mutex.synchronize do
        @buffers.each do |progname, severities|
          severities.each do |severity, buffer|
            messages += buffer.flush
          end
        end
      end
      messages.sort
    end

incident_topic() click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 125
    def incident_topic
      "log.incident.#{@progname}"
    end

info(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 97
    def info    (progname=nil, &block); add(INFO,    nil, progname, &block); end

log(severity, message=nil, progname=nil, &block) click to toggle source
Alias for: add
trace(progname=nil, &block) click to toggle source

See docs for Logger#info

    # File lib/celluloid/logging/incident_logger.rb, line 95
    def trace   (progname=nil, &block); add(TRACE,   nil, progname, &block); end

unknown(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 101
    def unknown (progname=nil, &block); add(UNKNOWN, nil, progname, &block); end

warn(progname=nil, &block) click to toggle source

    # File lib/celluloid/logging/incident_logger.rb, line 98
    def warn    (progname=nil, &block); add(WARN,    nil, progname, &block); end

[Validate]

Generated with the Darkfish Rdoc Generator 2.