/**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function convert($event)
 {
     $locationInfo = $event->getLocationInformation();
     switch ($this->type) {
         case Ideasa_Log4php_Helpers_LoggerPatternParser::FULL_LOCATION_CONVERTER:
             return $locationInfo->getFullInfo();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::METHOD_LOCATION_CONVERTER:
             return $locationInfo->getMethodName();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::LINE_LOCATION_CONVERTER:
             return $locationInfo->getLineNumber();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::FILE_LOCATION_CONVERTER:
             return $locationInfo->getFileName();
         case Ideasa_Log4php_Helpers_LoggerPatternParser::CLASS_LOCATION_CONVERTER:
             return $locationInfo->getFullQualifiedClassname();
         default:
             return '';
     }
 }
 /**
  * Converts the logging event into an array which can be logged to mongodb.
  * 
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return array The array representation of the logging event.
  */
 protected function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $timestampSec = (int) $event->getTimestamp();
     $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000);
     $document = array('timestamp' => new MongoDate($timestampSec, $timestampUsec), 'level' => $event->getLevel()->toString(), 'thread' => (int) $event->getThreadName(), 'message' => $event->getMessage(), 'loggerName' => $event->getLoggerName());
     $locationInfo = $event->getLocationInformation();
     if ($locationInfo != null) {
         $document['fileName'] = $locationInfo->getFileName();
         $document['method'] = $locationInfo->getMethodName();
         $document['lineNumber'] = $locationInfo->getLineNumber() == 'NA' ? 'NA' : (int) $locationInfo->getLineNumber();
         $document['className'] = $locationInfo->getClassName();
     }
     $throwableInfo = $event->getThrowableInformation();
     if ($throwableInfo != null) {
         $document['exception'] = $this->formatThrowable($throwableInfo->getThrowable());
     }
     return $document;
 }
예제 #3
0
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $sbuf = PHP_EOL . "<tr>" . PHP_EOL;
     $sbuf .= "<td>";
     $sbuf .= $event->getTime();
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">";
     $sbuf .= $event->getThreadName();
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"Level\">";
     $level = $event->getLevel();
     if ($level->equals(Ideasa_Log4php_LoggerLevel::getLevelDebug())) {
         $sbuf .= "<font color=\"#339933\">{$level}</font>";
     } else {
         if ($level->equals(Ideasa_Log4php_LoggerLevel::getLevelWarn())) {
             $sbuf .= "<font color=\"#993300\"><strong>{$level}</strong></font>";
         } else {
             $sbuf .= $level;
         }
     }
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">";
     $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES);
     $sbuf .= "</td>" . PHP_EOL;
     if ($this->locationInfo) {
         $locInfo = $event->getLocationInformation();
         $sbuf .= "<td>";
         $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES) . ':' . $locInfo->getLineNumber();
         $sbuf .= "</td>" . PHP_EOL;
     }
     $sbuf .= "<td title=\"Message\">";
     $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES);
     $sbuf .= "</td>" . PHP_EOL;
     $sbuf .= "</tr>" . PHP_EOL;
     if ($event->getNDC() != null) {
         $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">";
         $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES);
         $sbuf .= "</td></tr>" . PHP_EOL;
     }
     return $sbuf;
 }
예제 #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;
 }
예제 #5
0
 public function append(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->sp || $this->dry) {
         if ($this->getLocationInfo()) {
             $event->getLocationInformation();
         }
         if (!$this->getUseXml()) {
             $sEvent = serialize($event);
             if (!$this->dry) {
                 fwrite($this->sp, $sEvent, strlen($sEvent));
             } else {
                 echo "DRY MODE OF SOCKET APPENDER: " . $sEvent;
             }
         } else {
             if (!$this->dry) {
                 fwrite($this->sp, $this->xmlLayout->format($event));
             } else {
                 echo "DRY MODE OF SOCKET APPENDER: " . $this->xmlLayout->format($event);
             }
         }
         // not sure about it...
         if (!$this->dry) {
             fflush($this->sp);
         }
     }
 }