/**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function convert($event)
 {
     $timeStamp = $event->getTimeStamp();
     $usecs = round(($timeStamp - (int) $timeStamp) * 1000);
     $df = preg_replace('/((?<!\\\\)(?:\\\\{2})*)u/', '${1}' . sprintf('%03d', $usecs), $this->df);
     return date($df, $timeStamp);
 }
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function convert($event)
 {
     switch ($this->type) {
         case Ideasa_Log4php_Helpers_LoggerPatternParser::RELATIVE_TIME_CONVERTER:
             $timeStamp = $event->getTimeStamp();
             $startTime = Ideasa_Log4php_LoggerLoggingEvent::getStartTime();
             return (string) (int) ($timeStamp * 1000 - $startTime * 1000);
         case Ideasa_Log4php_Helpers_LoggerPatternParser::THREAD_CONVERTER:
             return $event->getThreadName();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::LEVEL_CONVERTER:
             $level = $event->getLevel();
             return $level->toString();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::NDC_CONVERTER:
             return $event->getNDC();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::MESSAGE_CONVERTER:
             return $event->getRenderedMessage();
         default:
             return '';
     }
 }
예제 #3
0
 /**
  * In addition to the level of the statement and message, the
  * returned string includes time, thread, category.
  * <p>Time, thread, category are printed depending on options.
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $timeStamp = (double) $event->getTimeStamp();
     $format = strftime($this->dateFormat, (int) $timeStamp);
     if ($this->microSecondsPrinting) {
         $usecs = floor(($timeStamp - (int) $timeStamp) * 1000);
         $format .= sprintf(',%03d', $usecs);
     }
     $format .= ' ';
     if ($this->threadPrinting) {
         $format .= '[' . getmypid() . '] ';
     }
     $level = $event->getLevel();
     $format .= $level . ' ';
     if ($this->categoryPrefixing) {
         $format .= $event->getLoggerName() . ' ';
     }
     if ($this->contextPrinting) {
         $ndc = $event->getNDC();
         if ($ndc != null) {
             $format .= $ndc . ' ';
         }
     }
     $format .= '- ' . $event->getRenderedMessage();
     $format .= PHP_EOL;
     return $format;
 }
예제 #4
0
 /**
  * Formats a {@link Ideasa_Log4php_LoggerLoggingEvent} in conformance with the log4php.dtd.
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $loggerName = $event->getLoggerName();
     $timeStamp = number_format((double) ($event->getTimeStamp() * 1000), 0, '', '');
     $thread = $event->getThreadName();
     $level = $event->getLevel();
     $levelStr = $level->toString();
     $buf = "<{$this->_namespacePrefix}:event logger=\"{$loggerName}\" level=\"{$levelStr}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">" . PHP_EOL;
     $buf .= "<{$this->_namespacePrefix}:message><![CDATA[";
     $this->appendEscapingCDATA($buf, $event->getRenderedMessage());
     $buf .= "]]></{$this->_namespacePrefix}:message>" . PHP_EOL;
     $ndc = $event->getNDC();
     if ($ndc != null) {
         $buf .= "<{$this->_namespacePrefix}:NDC><![CDATA[";
         $this->appendEscapingCDATA($buf, $ndc);
         $buf .= "]]></{$this->_namespacePrefix}:NDC>" . PHP_EOL;
     }
     if ($this->getLocationInfo()) {
         $locationInfo = $event->getLocationInformation();
         $buf .= "<{$this->_namespacePrefix}:locationInfo " . "class=\"" . $locationInfo->getClassName() . "\" " . "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" " . "line=\"" . $locationInfo->getLineNumber() . "\" " . "method=\"" . $locationInfo->getMethodName() . "\" ";
         $buf .= "/>" . PHP_EOL;
     }
     $buf .= "</{$this->_namespacePrefix}:event>" . PHP_EOL . PHP_EOL;
     return $buf;
 }