Back to Log class

Method addLoggerInternal

protected void
addLoggerInternal
(array $options, mixed $priorities = self::ALL, mixed $categories = array(), mixed $exclude = false)
Add a logger to the Log instance. Loggers route log entries to the correct files/systems to be logged.
Parameters
  • array $options The object configuration array.
  • int $priorities Message priority
  • array $categories Types of entry
  • bool $exclude If true, all categories will be logged except those in the $categories array
Returns
  • void
Since
  • 1.7.0
Class: Log
Project: Joomla

Method addLoggerInternal - Source code

/**
 * Add a logger to the Log instance.  Loggers route log entries to the correct files/systems to be logged.
 * This method allows you to extend Log completely.
 *
 * @param   array    $options     The object configuration array.
 * @param   integer  $priorities  Message priority
 * @param   array    $categories  Types of entry
 * @param   boolean  $exclude     If true, all categories will be logged except those in the $categories array
 *
 * @return  void
 *
 * @since   1.7.0
 */
protected function addLoggerInternal(array $options, $priorities = self::ALL, $categories = array(), $exclude = false)
{
    // The default logger is the formatted text log file.
    if (empty($options['logger'])) {
        $options['logger'] = 'formattedtext';
    }
    $options['logger'] = strtolower($options['logger']);
    // Special case - if a Closure object is sent as the callback (in case of CallbackLogger)
    // Closure objects are not serializable so swap it out for a unique id first then back again later
    if (isset($options['callback'])) {
        if (is_a($options['callback'], 'closure')) {
            $callback = $options['callback'];
            $options['callback'] = spl_object_hash($options['callback']);
        } elseif (\is_array($options['callback']) && \count($options['callback']) == 2 && \is_object($options['callback'][0])) {
            $callback = $options['callback'];
            $options['callback'] = spl_object_hash($options['callback'][0]) . '::' . $options['callback'][1];
        }
    }
    // Generate a unique signature for the Log instance based on its options.
    $signature = md5(serialize($options));
    // Now that the options array has been serialized, swap the callback back in
    if (isset($callback)) {
        $options['callback'] = $callback;
    }
    // Register the configuration if it doesn't exist.
    if (empty($this->configurations[$signature])) {
        $this->configurations[$signature] = $options;
    }
    $this->lookup[$signature] = (object) array('priorities' => $priorities, 'categories' => array_map('strtolower', (array) $categories), 'exclude' => (bool) $exclude);
}