コード例 #1
0
 /**
  * Handles the log message.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The message to be handled
  *
  * @return void
  */
 public function handle(LogMessageInterface $logMessage)
 {
     if ($this->shouldLog($logMessage->getLevel())) {
         // check the log level
         error_log($this->getFormatter()->format($logMessage) . PHP_EOL, 3, $this->getLogFile());
     }
 }
コード例 #2
0
 /**
  * Formats and returns a string representation of the passed log message.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to format
  *
  * @return string The formatted string representation for the log messsage
  */
 public function format(LogMessageInterface $logMessage)
 {
     // initialize the parameters for the formatted message
     $params = array(date($this->dateFormat), gethostname(), $logMessage->getLevel(), $logMessage->getMessage(), json_encode($logMessage->getContext()));
     // format, trim and return the message
     return trim(vsprintf($this->messageFormat, $params));
 }
コード例 #3
0
 /**
  * Handles the log message.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The message to be handled
  *
  * @return void
  */
 public function handle(LogMessageInterface $logMessage)
 {
     if ($this->shouldLog($logMessage->getLevel())) {
         // check the log level
         // the JSON encoded log message
         $jsonMessage = $this->getFormatter()->format($logMessage);
         // initialize a UDP socket
         $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
         // connect, write the message and close the socket
         socket_connect($socket, $this->getHost(), $this->getPort());
         socket_write($socket, $jsonMessage, strlen($jsonMessage));
         socket_close($socket);
     }
 }