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); } }
/** * 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; }