Ejemplo n.º 1
0
 /**
  * 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));
 }
Ejemplo n.º 2
0
 /**
  * {@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);
 }