You are here

class HttpblLogTrapper in http:BL 8

Same name in this branch
  1. 8 src/Logger/HttpblLogTrapper.php \Drupal\httpbl\Logger\HttpblLogTrapper
  2. 8 src/ProxyClass/Logger/HttpblLogTrapper.php \Drupal\httpbl\ProxyClass\Logger\HttpblLogTrapper

(An arbitrated logger)

HttpblLogTrapperInterface mimics LoggerInterface, adding a param that filters messages according to the Httpbl config setting for log volume ($logVolume). This allows verbose logging to be unconditionally added as needed, but then only passed on to the actual logger when the settings conditions apply.

The $logVolume param is NOT passed on when actual logging occurs.

The functions are all based on log levels compliant to RFC 5424 integers:

EMERGENCY = 0, ALERT = 1, CRITICAL = 2, ERROR = 3, WARNING = 4, NOTICE = 5, INFO = 6, DEBUG = 7.

Log volume filtering scheme: HTTPBL_LOG_QUIET = LogVolume 0 - Quiet - Passes levels 0 -- 3 HTTPBL_LOG_MIN = LogVolume 1 - Minimal - Passes levels 0 -- 5 HTTPBL_LOG_VERBOSE = LogVolume 2 - Verbose - Passes levels 0 -- 7

Hierarchy

Expanded class hierarchy of HttpblLogTrapper

See also

\Drupal\Core\Logger\RfcLogLevel

1 string reference to 'HttpblLogTrapper'
httpbl.services.yml in ./httpbl.services.yml
httpbl.services.yml
1 service uses HttpblLogTrapper
httpbl.logtrapper in ./httpbl.services.yml
Drupal\httpbl\Logger\HttpblLogTrapper

File

src/Logger/HttpblLogTrapper.php, line 34

Namespace

Drupal\httpbl\Logger
View source
class HttpblLogTrapper implements HttpblLogTrapperInterface {
  use RfcLoggerTrait;
  use DependencySerializationTrait;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * Logger service.
   *
   * @var \Drupal\Core\Logger\LoggerChannelInterface
   */
  protected $logger;

  /**
   * Constructs a HttpblLogtrapper object.
   *
   * @param \Drupal\Core\Logger\LogMessageParserInterface $parser
   *   The parser to use when extracting message variables.
   * @param \Drupal\Core\Logger\LoggerChannelInterface $logger
   *   The logger to add.
   */
  public function __construct(LogMessageParserInterface $parser, LoggerChannelInterface $logger) {
    $this->parser = $parser;
    $this->logger = $logger;
  }

  /**
   * {@inheritdoc}
   */
  public function trapEmergency($message, array $context = array(), $logVolume = HTTPBL_LOG_QUIET) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::EMERGENCY, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapAlert($message, array $context = array(), $logVolume = HTTPBL_LOG_QUIET) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::ALERT, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapCritical($message, array $context = array(), $logVolume = HTTPBL_LOG_QUIET) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::CRITICAL, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapError($message, array $context = array(), $logVolume = HTTPBL_LOG_QUIET) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::ERROR, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapWarning($message, array $context = array(), $logVolume = HTTPBL_LOG_MIN) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::WARNING, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapNotice($message, array $context = array(), $logVolume = HTTPBL_LOG_MIN) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::NOTICE, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapInfo($message, array $context = array(), $logVolume = HTTPBL_LOG_VERBOSE) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::INFO, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trapDebug($message, array $context = array(), $logVolume = HTTPBL_LOG_VERBOSE) {

    // Only pass message if logVolume meets or exceeds the minimum to pass on.
    if (\Drupal::state()
      ->get('httpbl.log') >= $logVolume) {
      $this
        ->log(RfcLogLevel::DEBUG, $message, $context);
    }
  }

  /**
   * {@inheritdoc}
   */
  public function log($level, $message, array $context = array()) {

    // Convert PSR3-style messages to SafeMarkup::format() style, so they can be
    // translated too in runtime.
    // @todo No longer using this for the time being.  Remove once certain it is
    // not needed.  Removal includes removing the parsing service from the
    // service container.
    $message_placeholders = $this->parser
      ->parseMessagePlaceholders($message, $context);
    switch ($level) {
      case 7:
        $method = 'debug';
        break;
      case 6:
        $method = 'info';
        break;
      case 5:
        $method = 'notice';
        break;
      case 4:
        $method = 'warning';
        break;
      case 3:
        $method = 'error';
        break;
      case 2:
        $method = 'critical';
        break;
      case 1:
        $method = 'alert';
        break;
      case 0:
        $method = 'emergency';
        break;
    }
    $this->logger
      ->{$method}($message, $context);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
HttpblLogTrapper::$logger protected property Logger service.
HttpblLogTrapper::$parser protected property The message's placeholders parser.
HttpblLogTrapper::log public function Overrides RfcLoggerTrait::log
HttpblLogTrapper::trapAlert public function Traps and forwards ALERT messages, based on config setting. Overrides HttpblLogTrapperInterface::trapAlert
HttpblLogTrapper::trapCritical public function Traps and forwards CRITICAL messages, based on config setting. Overrides HttpblLogTrapperInterface::trapCritical
HttpblLogTrapper::trapDebug public function Traps and forwards DEBUG messages, based on config setting. Overrides HttpblLogTrapperInterface::trapDebug
HttpblLogTrapper::trapEmergency public function Traps and forwards EMERGENCY messages, based on config setting. Overrides HttpblLogTrapperInterface::trapEmergency
HttpblLogTrapper::trapError public function Traps and forwards ERROR messages, based on config setting. Overrides HttpblLogTrapperInterface::trapError
HttpblLogTrapper::trapInfo public function Traps and forwards INFO messages, based on config setting. Overrides HttpblLogTrapperInterface::trapInfo
HttpblLogTrapper::trapNotice public function Traps and forwards NOTICE messages, based on config setting. Overrides HttpblLogTrapperInterface::trapNotice
HttpblLogTrapper::trapWarning public function Traps and forwards WARNING messages, based on config setting. Overrides HttpblLogTrapperInterface::trapWarning
HttpblLogTrapper::__construct public function Constructs a HttpblLogtrapper object.
RfcLoggerTrait::alert public function
RfcLoggerTrait::critical public function
RfcLoggerTrait::debug public function
RfcLoggerTrait::emergency public function
RfcLoggerTrait::error public function
RfcLoggerTrait::info public function
RfcLoggerTrait::notice public function
RfcLoggerTrait::warning public function