/**
  * @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);
 }
 /**
  * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match.
  */
 public function decide(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $msg = $event->getRenderedMessage();
     if ($msg === null or $this->stringToMatch === null) {
         return Ideasa_Log4php_LoggerFilter::NEUTRAL;
     }
     if (strpos($msg, $this->stringToMatch) !== false) {
         return $this->acceptOnMatch ? Ideasa_Log4php_LoggerFilter::ACCEPT : Ideasa_Log4php_LoggerFilter::DENY;
     }
     return Ideasa_Log4php_LoggerFilter::NEUTRAL;
 }
예제 #3
0
 public function append(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->layout !== null) {
         $level = $event->getLevel();
         if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelError())) {
             trigger_error($this->layout->format($event), E_USER_ERROR);
         } else {
             if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelWarn())) {
                 trigger_error($this->layout->format($event), E_USER_WARNING);
             } else {
                 trigger_error($this->layout->format($event), E_USER_NOTICE);
             }
         }
     }
 }
 /**
  * @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 '';
     }
 }
 /**
  * @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 '';
     }
 }
예제 #6
0
 /**
  * Returns the log statement in a format consisting of the
  * <b>level</b>, followed by " - " and then the
  * <b>message</b>. For example, 
  * <samp> INFO - "A message" </samp>
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $level = $event->getLevel();
     $message = $event->getRenderedMessage();
     return "{$level} - {$message}" . PHP_EOL;
 }
예제 #7
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;
 }
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function convert($event)
 {
     return $event->getMDC($this->key);
 }
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function getFullyQualifiedName($event)
 {
     return $event->getLoggerName();
 }
 /**
  * Return the decision of this filter.
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return integer
  */
 public function decide(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     $level = $event->getLevel();
     if ($this->levelMin !== null) {
         if ($level->isGreaterOrEqual($this->levelMin) == false) {
             // level of event is less than minimum
             return Ideasa_Log4php_LoggerFilter::DENY;
         }
     }
     if ($this->levelMax !== null) {
         if ($level->toInt() > $this->levelMax->toInt()) {
             // level of event is greater than maximum
             // Alas, there is no Level.isGreater method. and using
             // a combo of isGreaterOrEqual && !Equal seems worse than
             // checking the int values of the level objects..
             return Ideasa_Log4php_LoggerFilter::DENY;
         }
     }
     if ($this->acceptOnMatch) {
         // this filter set up to bypass later filters and always return
         // accept if level in range
         return Ideasa_Log4php_LoggerFilter::ACCEPT;
     } else {
         // event is ok for this filter; allow later filters to have a look..
         return Ideasa_Log4php_LoggerFilter::NEUTRAL;
     }
 }
예제 #11
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;
 }
예제 #12
0
 /**
  * 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;
 }
예제 #13
0
 /**
  * Override this method to create your own layout format.
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent
  * @return string
  */
 public function format(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     return $event->getRenderedMessage();
 }
예제 #14
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;
 }
예제 #15
0
 public function append(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->_option == NULL) {
         $this->_option = LOG_PID | LOG_CONS;
     }
     $level = $event->getLevel();
     if ($this->layout === null) {
         $message = $event->getRenderedMessage();
     } else {
         $message = $this->layout->format($event);
     }
     // If the priority of a syslog message can be overridden by a value defined in the properties-file,
     // use that value, else use the one that is defined in the code.
     if (!$this->dry) {
         // Attach the process ID to the message, use the facility defined in the .properties-file
         openlog($this->_ident, $this->_option, $this->_facility);
         if ($this->_overridePriority) {
             syslog($this->_priority, $message);
         } else {
             if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelFatal())) {
                 syslog(LOG_ALERT, $message);
             } else {
                 if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelError())) {
                     syslog(LOG_ERR, $message);
                 } else {
                     if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelWarn())) {
                         syslog(LOG_WARNING, $message);
                     } else {
                         if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelInfo())) {
                             syslog(LOG_INFO, $message);
                         } else {
                             if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelDebug())) {
                                 syslog(LOG_DEBUG, $message);
                             } else {
                                 if ($level->isGreaterOrEqual(Ideasa_Log4php_LoggerLevel::getLevelTrace())) {
                                     syslog(LOG_DEBUG, $message);
                                     // No trace level in syslog
                                 }
                             }
                         }
                     }
                 }
             }
         }
         closelog();
     } else {
         echo "DRY MODE OF SYSLOG APPENDER: " . $message;
     }
 }
 /**
  * Return the decision of this filter.
  * 
  * Returns {@link Ideasa_Log4php_LoggerFilter::NEUTRAL} if the <b><var>LevelToMatch</var></b>
  * option is not set or if there is not match.	Otherwise, if there is a
  * match, then the returned decision is {@link Ideasa_Log4php_LoggerFilter::ACCEPT} if the
  * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The
  * returned decision is {@link Ideasa_Log4php_LoggerFilter::DENY} if the
  * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>.
  *
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return integer
  */
 public function decide(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->levelToMatch === null) {
         return Ideasa_Log4php_LoggerFilter::NEUTRAL;
     }
     if ($this->levelToMatch->equals($event->getLevel())) {
         return $this->acceptOnMatch ? Ideasa_Log4php_LoggerFilter::ACCEPT : Ideasa_Log4php_LoggerFilter::DENY;
     } else {
         return Ideasa_Log4php_LoggerFilter::NEUTRAL;
     }
 }
예제 #17
0
 /**
  * This method performs threshold checks and invokes filters before
  * delegating actual logging to the subclasses specific <i>append()</i> method.
  * @see Ideasa_Log4php_LoggerAppender::doAppend()
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  */
 public function doAppend(Ideasa_Log4php_LoggerLoggingEvent $event)
 {
     if ($this->closed) {
         return;
     }
     if (!$this->isAsSevereAsThreshold($event->getLevel())) {
         return;
     }
     $f = $this->getFirstFilter();
     while ($f !== null) {
         switch ($f->decide($event)) {
             case Ideasa_Log4php_LoggerFilter::DENY:
                 return;
             case Ideasa_Log4php_LoggerFilter::ACCEPT:
                 return $this->append($event);
             case Ideasa_Log4php_LoggerFilter::NEUTRAL:
                 $f = $f->getNext();
         }
     }
     $this->append($event);
 }
 /**
  * @param Ideasa_Log4php_LoggerLoggingEvent $event
  * @return string
  */
 public function getFullyQualifiedName($event)
 {
     return $event->getFullQualifiedClassname();
 }
예제 #19
0
 /**
  * Calculates the time of this event.
  * @return the time after event starttime when this event has occured
  */
 public function getTime()
 {
     $eventTime = (double) $this->getTimeStamp();
     $eventStartTime = (double) Ideasa_Log4php_LoggerLoggingEvent::getStartTime();
     return number_format(($eventTime - $eventStartTime) * 1000, 0, '', '');
 }
예제 #20
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);
         }
     }
 }