Module: Hoodoo::Logger::Communicator

Included in:
FastCommunicator, SlowCommunicator
Defined in:
lib/hoodoo/logger/logger.rb

Overview

Mixin used internally for the FastCommunicator and SlowCommunicator wrappers that hide implementation complexity from log writer subclasses.

Instance Method Summary collapse

Instance Method Details

#communicate(payload) ⇒ Object

Implement Hoodoo::Communicators::Base#communicate for both slow and fast writers. Assumes it will be passed a Hoodoo::Logger::Payload class instance which describes the structured log data to report; also assumes it is only called when the calling logger’s configured log level threshold should allow through the level of the log message in question. Calls through to the #report implementation.



381
382
383
384
385
386
387
388
# File 'lib/hoodoo/logger/logger.rb', line 381

def communicate( payload )
  @writer_instance.report(
    payload.log_level,
    payload.component,
    payload.code,
    payload.data
  )
end

#dropped(number) ⇒ Object

Implement optional method Hoodoo::Communicators::Slow#dropped on behalf of subclasses. The method turns the ‘messages dropped’ notification into a log message of :warn level and which it reports internally immediately for the Writer instance only (since different writers have different queues and thus different dropped message warnings), provided that the owning Hoodoo::Logger instance log level lets warnings through.



398
399
400
401
402
403
404
405
406
407
# File 'lib/hoodoo/logger/logger.rb', line 398

def dropped( number )
  if @owning_logger.report?( :warn )
    @writer_instance.report(
      :warn,
      self.class.name,
      'dropped.messages',
      "Logging flooded - #{ number } messages dropped"
    )
  end
end

#initialize(writer_instance, owning_logger) ⇒ Object

Create an instance of a logging communicator, based on the given log writer and owning logger instance.

writer_instance

Hoodoo::Logger::FastWriter or Hoodoo::Logger::SlowWriter subclass instance that will log things when this Communicator asks it to do so.

owning_logger

Hoodoo::Logger instance that will be using this communicator instance.



369
370
371
372
# File 'lib/hoodoo/logger/logger.rb', line 369

def initialize( writer_instance, owning_logger )
  @writer_instance = writer_instance
  @owning_logger   = owning_logger
end