Exemplo n.º 1
0
 /**
  * Logs the message
  *
  * @param \YapepBase\Log\Message\IMessage $message The message to log.
  *
  * @return void
  */
 protected function logMessage(IMessage $message)
 {
     if ($message->getPriority() <= $this->minimumLogLevel) {
         $handle = fopen('php://stderr', 'a');
         fwrite($handle, sprintf("%s %s(%d) [%s]: %s %s\n", date('d-M-Y H:i:s'), str_pad($this->logLevelHelper->getTextFromLevel($message->getPriority()), 5), $message->getPriority(), str_pad($message->getTag(), 20), $message->getMessage(), count($message->getFields()) > 0 ? sprintf('(DATA: "%s")', json_encode($message->getFields())) : ''));
         fclose($handle);
     }
 }
Exemplo n.º 2
0
 /**
  * Returns the log message prepared from the message
  *
  * @param \YapepBase\Log\Message\IMessage $message   The message to log.
  *
  * @return string
  */
 protected function getLogMessage(IMessage $message)
 {
     $fields = $message->getFields();
     $logMessage = '[' . $message->getTag() . ']|';
     foreach ($fields as $key => $value) {
         $logMessage .= $key . '=' . $value . '|';
     }
     // We have to remove the line breaks, because syslog will create new log entry after every linebreak.
     $message = str_replace(PHP_EOL, '', $logMessage . 'message=' . $message->getMessage());
     return $message;
 }