/** * Replace any '{item}' in the messsage with context['item'] value * * @see http://www.php-fig.org/psr/psr-3/ */ public function __invoke(LogEntryInterface $log) { $msg = $log->getMessage(); if (strpos($msg, '{') === false) { return; } // build a replacement array with braces around the context keys $replace = []; $context = $log->getContexts(); foreach ($context as $key => $val) { if (is_object($val)) { if ($val instanceof \Exception) { $xval = 'EXCEPTION: ' . $val->getMessage(); } elseif (method_exists($val, '__toString')) { $xval = (string) $val; } else { $xval = 'OBJECT: ' . get_class($val); } } elseif (is_scalar($val)) { $xval = strval($val); } else { $xval = 'TYPE: ' . strtoupper(gettype($val)); } $replace['{' . $key . '}'] = $xval; } // interpolate replacement values into the message $log->setMessage(strtr($msg, $replace)); }
/** * {@inheritDoc} */ public function __invoke(LogEntryInterface $log) { // open syslog if (!openlog($this->ident, $this->options, $this->facility)) { throw new Exception\InvalidArgumentException(Message::get(Message::INVALID_LOG_SYSLOG, $this->ident, $this->facility), Message::INVALID_LOG_SYSLOG); } // write syslog syslog($this->map[$log->getLevel()], call_user_func($this->getFormatter(), $log)); // close syslog closelog(); }
/** * {@inheritDoc} */ public function __invoke(LogEntryInterface $log) { $data = ['%datetime%' => date('Y-m-d H:i:s', $log->getTimestamp()), '%channel%' => $log->getContext('__CHANNEL__'), '%level_name%' => strtoupper($log->getLevel()), '%message%' => $log->getMessage(), '%context%' => $this->printContext($log->getContexts())]; return strtr($this->format, $data); }