public function convert(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->useLocalDate) { return $this->date($this->format, $event->getTimeStamp()); } return date($this->format, $event->getTimeStamp()); }
public function format(Payone_Log4php_LoggerLoggingEvent $event) { // If required, initialize the location data if ($this->locationInfo) { $event->getLocationInformation(); } return serialize($event) . PHP_EOL; }
/** * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. */ public function decide(Payone_Log4php_LoggerLoggingEvent $event) { $msg = $event->getRenderedMessage(); if ($msg === null or $this->stringToMatch === null) { return Payone_Log4php_LoggerFilter::NEUTRAL; } if (strpos($msg, $this->stringToMatch) !== false) { return $this->acceptOnMatch ? Payone_Log4php_LoggerFilter::ACCEPT : Payone_Log4php_LoggerFilter::DENY; } return Payone_Log4php_LoggerFilter::NEUTRAL; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { $name = $event->getLoggerName(); if (!isset($this->cache[$name])) { // If length is set return shortened logger name if (isset($this->length)) { $this->cache[$name] = $this->shorten($name, $this->length); } else { $this->cache[$name] = $name; } } return $this->cache[$name]; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { if (isset($this->key)) { return $event->getMDC($this->key); } else { $buff = array(); $map = $event->getMDCMap(); foreach ($map as $key => $value) { $buff[] = "{$key}={$value}"; } return implode(', ', $buff); } }
public function append(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->layout !== null) { $level = $event->getLevel(); if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelError())) { trigger_error($this->layout->format($event), E_USER_ERROR); } else { if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelWarn())) { trigger_error($this->layout->format($event), E_USER_WARNING); } else { trigger_error($this->layout->format($event), E_USER_NOTICE); } } } }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { $info = $event->getThrowableInformation(); if ($info === null) { return ''; } $ex = $info->getThrowable(); // Format exception to string $strEx = get_class($ex) . ': "' . $ex->getMessage() . '"' . PHP_EOL; $strEx .= 'at ' . $ex->getFile() . ':' . $ex->getLine(); // Add trace if required if ($this->depth === null || $this->depth > 0) { $trace = $ex->getTrace(); foreach ($trace as $key => $item) { if (isset($this->depth) && $key > $this->depth) { break; } $strEx .= PHP_EOL . "#{$key} " . "{$item['file']}:{$item['line']} " . "in {$item['class']}{$item['type']}{$item['function']}()"; } } return $strEx; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getRenderedMessage(); }
/** * @param Payone_Log4php_LoggerLoggingEvent $event * @return string */ public function format(Payone_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(Payone_Log4php_LoggerLevel::getLevelDebug())) { $sbuf .= "<font color=\"#339933\">{$level}</font>"; } else { if ($level->equals(Payone_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; }
/** * Performs threshold checks and invokes filters before delegating logging * to the subclass' specific <i>append()</i> method. * @see Payone_Log4php_LoggerAppender::append() * @param Payone_Log4php_LoggerLoggingEvent $event */ public function doAppend(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->closed) { return; } if (!$this->isAsSevereAsThreshold($event->getLevel())) { return; } $f = $this->getFirstFilter(); while ($f !== null) { switch ($f->decide($event)) { case Payone_Log4php_LoggerFilter::DENY: return; case Payone_Log4php_LoggerFilter::ACCEPT: return $this->append($event); case Payone_Log4php_LoggerFilter::NEUTRAL: $f = $f->getNext(); } } $this->append($event); }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getLocationInformation()->getMethodName(); }
/** * Converts the logging event into an array which can be logged to mongodb. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return array The array representation of the logging event. */ protected function format(Payone_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; }
/** * 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 Payone_Log4php_LoggerLoggingEvent $event * @return string */ public function format(Payone_Log4php_LoggerLoggingEvent $event) { $level = $event->getLevel(); $message = $event->getRenderedMessage(); return "{$level} - {$message}" . PHP_EOL; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getLocationInformation()->getLineNumber(); }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getNDC(); }
/** * Appends the event to syslog. * * Log is opened and closed each time because if it is not closed, it * can cause the Apache httpd server to log to whatever ident/facility * was used in openlog(). * * @see http://www.php.net/manual/en/function.syslog.php#97843 */ public function append(Payone_Log4php_LoggerLoggingEvent $event) { $priority = $this->getSyslogPriority($event->getLevel()); $message = $this->layout->format($event); openlog($this->ident, $this->intOption, $this->intFacility); syslog($priority, $message); closelog(); }
/** * Return the decision of this filter. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return integer */ public function decide(Payone_Log4php_LoggerLoggingEvent $event) { $level = $event->getLevel(); if ($this->levelMin !== null) { if ($level->isGreaterOrEqual($this->levelMin) == false) { // level of event is less than minimum return Payone_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 Payone_Log4php_LoggerFilter::DENY; } } if ($this->acceptOnMatch) { // this filter set up to bypass later filters and always return // accept if level in range return Payone_Log4php_LoggerFilter::ACCEPT; } else { // event is ok for this filter; allow later filters to have a look.. return Payone_Log4php_LoggerFilter::NEUTRAL; } }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getLocationInformation()->getClassName() . '.' . $event->getLocationInformation()->getMethodName() . '(' . $event->getLocationInformation()->getFileName() . ':' . $event->getLocationInformation()->getLineNumber() . ')'; }
/** * Calculates the time of this event. * @return the time after event starttime when this event has occured */ public function getTime() { $eventTime = $this->getTimeStamp(); $eventStartTime = Payone_Log4php_LoggerLoggingEvent::getStartTime(); return number_format(($eventTime - $eventStartTime) * 1000, 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 Payone_Log4php_LoggerLoggingEvent $event * @return string */ public function format(Payone_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; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { return $event->getLevel()->toString(); }
/** * Return the decision of this filter. * * Returns {@link 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 LoggerFilter::ACCEPT} if the * <b><var>AcceptOnMatch</var></b> property is set to <i>true</i>. The * returned decision is {@link LoggerFilter::DENY} if the * <b><var>AcceptOnMatch</var></b> property is set to <i>false</i>. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return integer */ public function decide(Payone_Log4php_LoggerLoggingEvent $event) { if ($this->levelToMatch === null) { return Payone_Log4php_LoggerFilter::NEUTRAL; } if ($this->levelToMatch->equals($event->getLevel())) { return $this->acceptOnMatch ? Payone_Log4php_LoggerFilter::ACCEPT : Payone_Log4php_LoggerFilter::DENY; } else { return Payone_Log4php_LoggerFilter::NEUTRAL; } }
/** * Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd. * * @param Payone_Log4php_LoggerLoggingEvent $event * @return string */ public function format(Payone_Log4php_LoggerLoggingEvent $event) { $ns = $this->namespacePrefix; $loggerName = $event->getLoggerName(); $timeStamp = number_format((double) ($event->getTimeStamp() * 1000), 0, '', ''); $thread = $event->getThreadName(); $level = $event->getLevel()->toString(); $buf = "<{$ns}:event logger=\"{$loggerName}\" level=\"{$level}\" thread=\"{$thread}\" timestamp=\"{$timeStamp}\">" . PHP_EOL; $buf .= "<{$ns}:message>"; $buf .= $this->encodeCDATA($event->getRenderedMessage()); $buf .= "</{$ns}:message>" . PHP_EOL; $ndc = $event->getNDC(); if (!empty($ndc)) { $buf .= "<{$ns}:NDC><![CDATA["; $buf .= $this->encodeCDATA($ndc); $buf .= "]]></{$ns}:NDC>" . PHP_EOL; } $mdcMap = $event->getMDCMap(); if (!empty($mdcMap)) { $buf .= "<{$ns}:properties>" . PHP_EOL; foreach ($mdcMap as $name => $value) { $buf .= "<{$ns}:data name=\"{$name}\" value=\"{$value}\" />" . PHP_EOL; } $buf .= "</{$ns}:properties>" . PHP_EOL; } if ($this->getLocationInfo()) { $locationInfo = $event->getLocationInformation(); $buf .= "<{$ns}:locationInfo " . "class=\"" . $locationInfo->getClassName() . "\" " . "file=\"" . htmlentities($locationInfo->getFileName(), ENT_QUOTES) . "\" " . "line=\"" . $locationInfo->getLineNumber() . "\" " . "method=\"" . $locationInfo->getMethodName() . "\" "; $buf .= "/>" . PHP_EOL; } $buf .= "</{$ns}:event>" . PHP_EOL; return $buf; }
public function convert(Payone_Log4php_LoggerLoggingEvent $event) { $ts = $event->getTimeStamp() - $event->getStartTime(); return number_format($ts, 4); }