Пример #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
 /**
  * Adds the actual system load to the log message context.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the system load
  *
  * @return string The processed log message
  * @see \AppserverIo\Logger\Processors\ProcessorInterface::process()
  */
 public function process(LogMessageInterface $logMessage)
 {
     // load the sysload values
     $values = sys_getloadavg();
     // create an array
     $sysload = array('system_load_1' => array_shift($values), 'system_load_5' => array_shift($values), 'system_load_15' => array_shift($values));
     // merge the values with the actual context instance
     $logMessage->mergeIntoContext($sysload);
 }
Пример #3
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));
 }
 /**
  * Adds the debug backtrace to the log message context.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the debug backtrace
  *
  * @return string The processed log messsage
  */
 public function process(LogMessageInterface $logMessage)
 {
     $logMessage->appendToContext(DebugBacktraceProcessor::CONTEXT_KEY, debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));
 }
Пример #5
0
 /**
  * Adds the actual memory usage to the log message context.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the memory usage
  *
  * @return string The processed log messsage
  * @see \AppserverIo\Logger\Processors\ProcessorInterface::process()
  */
 public function process(LogMessageInterface $logMessage)
 {
     $logMessage->appendToContext(MemoryProcessor::CONTEXT_KEY, memory_get_usage());
 }
Пример #6
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);
     }
 }
 /**
  * Adds the thread context as name attribute to the log message context.
  *
  * @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the thread context name to
  *
  * @return string The processed log message
  * @see \AppserverIo\Logger\Processors\ProcessorInterface::process()
  */
 public function process(LogMessageInterface $logMessage)
 {
     $logMessage->appendToContext(ThreadContextProcessor::CONTEXT_KEY, Logger::$threadContext);
 }