Back to DelegatingPsrLogger class

Method log

public void
log
(mixed $level, mixed $message, array $context = array())
Logs with an arbitrary level.
Parameters
  • mixed $level The log level.
  • string $message The log message.
  • array $context Additional message context.
Returns
  • void
Since
  • 3.8.0
-
  • \Psr\Log\InvalidArgumentException

Method log - Source code

/**
 * Logs with an arbitrary level.
 *
 * @param   mixed   $level    The log level.
 * @param   string  $message  The log message.
 * @param   array   $context  Additional message context.
 *
 * @return  void
 *
 * @since   3.8.0
 * @throws  InvalidArgumentException
 */
public function log($level, $message, array $context = array())
{
    // Make sure the log level is valid
    if (!\array_key_exists($level, $this->priorityMap)) {
        throw new \InvalidArgumentException('An invalid log level has been given.');
    }
    // Map the level to Joomla's priority
    $priority = $this->priorityMap[$level];
    $category = null;
    $date = null;
    // If a message category is given, map it
    if (!empty($context['category'])) {
        $category = $context['category'];
    }
    // If a message timestamp is given, map it
    if (!empty($context['date'])) {
        $date = $context['date'];
    }
    // Joomla's logging API will only process a string or a LogEntry object, if $message is an object without __toString() we can't use it
    if (!\is_string($message) && !$message instanceof LogEntry) {
        if (!\is_object($message) || !method_exists($message, '__toString')) {
            throw new \InvalidArgumentException('The message must be a string, a LogEntry object, or an object implementing the __toString() method.');
        }
        $message = (string) $message;
    }
    $this->logger->add($message, $priority, $category, $date, $context);
}