You are here

function monolog_push_handlers in Monolog 6

Same name and namespace in other branches
  1. 7 monolog.module \monolog_push_handlers()

Pushes handlers onto the stack.

Parameters

Logger $logger: The logger that handlers are being pushed onto.

stdClass $profile: The logging profile configuration.

Throws

\InvalidArgumentException

1 call to monolog_push_handlers()
monolog in ./monolog.module
Factory function for Monolog loggers.

File

./monolog.module, line 224
A Framework and UI for integrating with the Monolog library.

Code

function monolog_push_handlers(Logger $logger, stdClass $profile) {

  // Reverse the handlers since they are pushed onto the stack. This allows
  // handlers at the top of the table to be processed first.
  $handlers = array_reverse($profile->options['handlers']);
  foreach ($handlers as $handler_name => $handler_config) {
    $handler_info = monolog_handler_info_load($handler_config['handler']);
    if (!$handler_info) {
      $message = t('Monolog handler not valid: @handler', array(
        '@handler' => $handler_config['handler'],
      ));
      throw new \InvalidArgumentException($message);
    }
    monolog_load_handler_include($handler_info);
    if (!function_exists($handler_info['loader callback'])) {
      $message = t('Function not defined: @function', array(
        '@function' => $handler_info['loader callback'],
      ));
      throw new \InvalidArgumentException($message);
    }
    $handler_config['bubble'] = (bool) $handler_config['bubble'];
    $handler = $handler_info['loader callback']($handler_config);
    $logger
      ->pushHandler($handler);
  }
}