示例#1
0
 /**
  * Logs the message
  *
  * @param \YapepBase\Log\Message\IMessage $message   The message to log.
  *
  * @return void
  *
  * @throws \YapepBase\Exception\Log\LoggerNotFoundException   If there are no registered Loggers in the registry.
  */
 public function log(IMessage $message)
 {
     if (!$message->checkIsEmpty()) {
         if (empty($this->loggers)) {
             throw new LoggerNotFoundException('There are no registered Loggers!');
         }
         foreach ($this->loggers as $logger) {
             /** @var ILogger $logger */
             $logger->log($message);
         }
     }
 }
 /**
  * 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);
     }
 }
示例#3
0
 /**
  * Logs the message
  *
  * @param \YapepBase\Log\Message\IMessage $message   The message to log.
  *
  * @return void
  */
 public function log(IMessage $message)
 {
     if (!$message->checkIsEmpty()) {
         $this->logMessage($message);
     }
 }
示例#4
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;
 }