mirror of
https://github.com/ZeJMaN/LBCAlerte_ynh.git
synced 2025-07-06 11:50:48 +02:00
Initial commit
Functional, without SSO
This commit is contained in:
214
sources/lib/Log4php/layouts/LoggerLayoutHtml.php
Normal file
214
sources/lib/Log4php/layouts/LoggerLayoutHtml.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* This layout outputs events in a HTML table.
|
||||
*
|
||||
* Configurable parameters for this layout are:
|
||||
*
|
||||
* - title
|
||||
* - locationInfo
|
||||
*
|
||||
* An example for this layout:
|
||||
*
|
||||
* {@example ../../examples/php/layout_html.php 19}<br>
|
||||
*
|
||||
* The corresponding XML file:
|
||||
*
|
||||
* {@example ../../examples/resources/layout_html.properties 18}
|
||||
*
|
||||
* The above will print a HTML table that looks, converted back to plain text, like the following:<br>
|
||||
* <pre>
|
||||
* Log session start time Wed Sep 9 00:11:30 2009
|
||||
*
|
||||
* Time Thread Level Category Message
|
||||
* 0 8318 INFO root Hello World!
|
||||
* </pre>
|
||||
*
|
||||
* @version $Revision: 1379731 $
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
*/
|
||||
class LoggerLayoutHtml extends LoggerLayout {
|
||||
/**
|
||||
* The <b>LocationInfo</b> option takes a boolean value. By
|
||||
* default, it is set to false which means there will be no location
|
||||
* information output by this layout. If the the option is set to
|
||||
* true, then the file name and line number of the statement
|
||||
* at the origin of the log statement will be output.
|
||||
*
|
||||
* <p>If you are embedding this layout within a {@link LoggerAppenderMail}
|
||||
* or a {@link LoggerAppenderMailEvent} then make sure to set the
|
||||
* <b>LocationInfo</b> option of that appender as well.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $locationInfo = false;
|
||||
|
||||
/**
|
||||
* The <b>Title</b> option takes a String value. This option sets the
|
||||
* document title of the generated HTML document.
|
||||
* Defaults to 'Log4php Log Messages'.
|
||||
* @var string
|
||||
*/
|
||||
protected $title = "Log4php Log Messages";
|
||||
|
||||
/**
|
||||
* The <b>LocationInfo</b> option takes a boolean value. By
|
||||
* default, it is set to false which means there will be no location
|
||||
* information output by this layout. If the the option is set to
|
||||
* true, then the file name and line number of the statement
|
||||
* at the origin of the log statement will be output.
|
||||
*
|
||||
* <p>If you are embedding this layout within a {@link LoggerAppenderMail}
|
||||
* or a {@link LoggerAppenderMailEvent} then make sure to set the
|
||||
* <b>LocationInfo</b> option of that appender as well.
|
||||
*/
|
||||
public function setLocationInfo($flag) {
|
||||
$this->setBoolean('locationInfo', $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of the <b>LocationInfo</b> option.
|
||||
*/
|
||||
public function getLocationInfo() {
|
||||
return $this->locationInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>Title</b> option takes a String value. This option sets the
|
||||
* document title of the generated HTML document.
|
||||
* Defaults to 'Log4php Log Messages'.
|
||||
*/
|
||||
public function setTitle($title) {
|
||||
$this->setString('title', $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Returns the current value of the <b>Title</b> option.
|
||||
*/
|
||||
public function getTitle() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Returns the content type output by this layout, i.e "text/html".
|
||||
*/
|
||||
public function getContentType() {
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LoggerLoggingEvent $event
|
||||
* @return string
|
||||
*/
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
$sbuf = PHP_EOL . "<tr>" . PHP_EOL;
|
||||
|
||||
$sbuf .= "<td>";
|
||||
$sbuf .= round(1000 * $event->getRelativeTime());
|
||||
$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(LoggerLevel::getLevelDebug())) {
|
||||
$sbuf .= "<font color=\"#339933\">$level</font>";
|
||||
} else if ($level->equals(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Returns appropriate HTML headers.
|
||||
*/
|
||||
public function getHeader() {
|
||||
$sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . PHP_EOL;
|
||||
$sbuf .= "<html>" . PHP_EOL;
|
||||
$sbuf .= "<head>" . PHP_EOL;
|
||||
$sbuf .= "<title>" . $this->title . "</title>" . PHP_EOL;
|
||||
$sbuf .= "<style type=\"text/css\">" . PHP_EOL;
|
||||
$sbuf .= "<!--" . PHP_EOL;
|
||||
$sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . PHP_EOL;
|
||||
$sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . PHP_EOL;
|
||||
$sbuf .= "-->" . PHP_EOL;
|
||||
$sbuf .= "</style>" . PHP_EOL;
|
||||
$sbuf .= "</head>" . PHP_EOL;
|
||||
$sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . PHP_EOL;
|
||||
$sbuf .= "<hr size=\"1\" noshade>" . PHP_EOL;
|
||||
$sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . PHP_EOL;
|
||||
$sbuf .= "<br>" . PHP_EOL;
|
||||
$sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . PHP_EOL;
|
||||
$sbuf .= "<tr>" . PHP_EOL;
|
||||
$sbuf .= "<th>Time</th>" . PHP_EOL;
|
||||
$sbuf .= "<th>Thread</th>" . PHP_EOL;
|
||||
$sbuf .= "<th>Level</th>" . PHP_EOL;
|
||||
$sbuf .= "<th>Category</th>" . PHP_EOL;
|
||||
if ($this->locationInfo) {
|
||||
$sbuf .= "<th>File:Line</th>" . PHP_EOL;
|
||||
}
|
||||
$sbuf .= "<th>Message</th>" . PHP_EOL;
|
||||
$sbuf .= "</tr>" . PHP_EOL;
|
||||
|
||||
return $sbuf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Returns the appropriate HTML footers.
|
||||
*/
|
||||
public function getFooter() {
|
||||
$sbuf = "</table>" . PHP_EOL;
|
||||
$sbuf .= "<br>" . PHP_EOL;
|
||||
$sbuf .= "</body></html>";
|
||||
|
||||
return $sbuf;
|
||||
}
|
||||
}
|
171
sources/lib/Log4php/layouts/LoggerLayoutPattern.php
Normal file
171
sources/lib/Log4php/layouts/LoggerLayoutPattern.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* A flexible layout configurable with a pattern string.
|
||||
*
|
||||
* Configurable parameters:
|
||||
*
|
||||
* * converionPattern - A string which controls the formatting of logging
|
||||
* events. See docs for full specification.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
* @version $Revision: 1395470 $
|
||||
*/
|
||||
class LoggerLayoutPattern extends LoggerLayout {
|
||||
|
||||
/** Default conversion pattern */
|
||||
const DEFAULT_CONVERSION_PATTERN = '%date %-5level %logger %message%newline';
|
||||
|
||||
/** Default conversion TTCC Pattern */
|
||||
const TTCC_CONVERSION_PATTERN = '%d [%t] %p %c %x - %m%n';
|
||||
|
||||
/** The conversion pattern. */
|
||||
protected $pattern = self::DEFAULT_CONVERSION_PATTERN;
|
||||
|
||||
/** Maps conversion keywords to the relevant converter (default implementation). */
|
||||
protected static $defaultConverterMap = array(
|
||||
'c' => 'LoggerPatternConverterLogger',
|
||||
'lo' => 'LoggerPatternConverterLogger',
|
||||
'logger' => 'LoggerPatternConverterLogger',
|
||||
|
||||
'C' => 'LoggerPatternConverterClass',
|
||||
'class' => 'LoggerPatternConverterClass',
|
||||
|
||||
'cookie' => 'LoggerPatternConverterCookie',
|
||||
|
||||
'd' => 'LoggerPatternConverterDate',
|
||||
'date' => 'LoggerPatternConverterDate',
|
||||
|
||||
'e' => 'LoggerPatternConverterEnvironment',
|
||||
'env' => 'LoggerPatternConverterEnvironment',
|
||||
|
||||
'ex' => 'LoggerPatternConverterThrowable',
|
||||
'exception' => 'LoggerPatternConverterThrowable',
|
||||
'throwable' => 'LoggerPatternConverterThrowable',
|
||||
|
||||
'F' => 'LoggerPatternConverterFile',
|
||||
'file' => 'LoggerPatternConverterFile',
|
||||
|
||||
'l' => 'LoggerPatternConverterLocation',
|
||||
'location' => 'LoggerPatternConverterLocation',
|
||||
|
||||
'L' => 'LoggerPatternConverterLine',
|
||||
'line' => 'LoggerPatternConverterLine',
|
||||
|
||||
'm' => 'LoggerPatternConverterMessage',
|
||||
'msg' => 'LoggerPatternConverterMessage',
|
||||
'message' => 'LoggerPatternConverterMessage',
|
||||
|
||||
'M' => 'LoggerPatternConverterMethod',
|
||||
'method' => 'LoggerPatternConverterMethod',
|
||||
|
||||
'n' => 'LoggerPatternConverterNewLine',
|
||||
'newline' => 'LoggerPatternConverterNewLine',
|
||||
|
||||
'p' => 'LoggerPatternConverterLevel',
|
||||
'le' => 'LoggerPatternConverterLevel',
|
||||
'level' => 'LoggerPatternConverterLevel',
|
||||
|
||||
'r' => 'LoggerPatternConverterRelative',
|
||||
'relative' => 'LoggerPatternConverterRelative',
|
||||
|
||||
'req' => 'LoggerPatternConverterRequest',
|
||||
'request' => 'LoggerPatternConverterRequest',
|
||||
|
||||
's' => 'LoggerPatternConverterServer',
|
||||
'server' => 'LoggerPatternConverterServer',
|
||||
|
||||
'ses' => 'LoggerPatternConverterSession',
|
||||
'session' => 'LoggerPatternConverterSession',
|
||||
|
||||
'sid' => 'LoggerPatternConverterSessionID',
|
||||
'sessionid' => 'LoggerPatternConverterSessionID',
|
||||
|
||||
't' => 'LoggerPatternConverterProcess',
|
||||
'pid' => 'LoggerPatternConverterProcess',
|
||||
'process' => 'LoggerPatternConverterProcess',
|
||||
|
||||
'x' => 'LoggerPatternConverterNDC',
|
||||
'ndc' => 'LoggerPatternConverterNDC',
|
||||
|
||||
'X' => 'LoggerPatternConverterMDC',
|
||||
'mdc' => 'LoggerPatternConverterMDC',
|
||||
);
|
||||
|
||||
/** Maps conversion keywords to the relevant converter. */
|
||||
protected $converterMap = array();
|
||||
|
||||
/**
|
||||
* Head of a chain of Converters.
|
||||
* @var LoggerPatternConverter
|
||||
*/
|
||||
private $head;
|
||||
|
||||
/** Returns the default converter map. */
|
||||
public static function getDefaultConverterMap() {
|
||||
return self::$defaultConverterMap;
|
||||
}
|
||||
|
||||
/** Constructor. Initializes the converter map. */
|
||||
public function __construct() {
|
||||
$this->converterMap = self::$defaultConverterMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the conversionPattern option. This is the string which
|
||||
* controls formatting and consists of a mix of literal content and
|
||||
* conversion specifiers.
|
||||
* @param array $conversionPattern
|
||||
*/
|
||||
public function setConversionPattern($conversionPattern) {
|
||||
$this->pattern = $conversionPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the conversion pattern and creates a corresponding chain of
|
||||
* pattern converters which will be used to format logging events.
|
||||
*/
|
||||
public function activateOptions() {
|
||||
if (!isset($this->pattern)) {
|
||||
throw new LoggerException("Mandatory parameter 'conversionPattern' is not set.");
|
||||
}
|
||||
|
||||
$parser = new LoggerPatternParser($this->pattern, $this->converterMap);
|
||||
$this->head = $parser->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces a formatted string as specified by the conversion pattern.
|
||||
*
|
||||
* @param LoggerLoggingEvent $event
|
||||
* @return string
|
||||
*/
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
$sbuf = '';
|
||||
$converter = $this->head;
|
||||
while ($converter !== null) {
|
||||
$converter->format($sbuf, $event);
|
||||
$converter = $converter->next;
|
||||
}
|
||||
return $sbuf;
|
||||
}
|
||||
}
|
55
sources/lib/Log4php/layouts/LoggerLayoutSerialized.php
Normal file
55
sources/lib/Log4php/layouts/LoggerLayoutSerialized.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* Layout which formats the events using PHP's serialize() function.
|
||||
*
|
||||
* Available options:
|
||||
* - locationInfo - If set to true, the event's location information will also
|
||||
* be serialized (slow, defaults to false).
|
||||
*
|
||||
* @version $Revision: 1334369 $
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
* @since 2.2
|
||||
*/
|
||||
class LoggerLayoutSerialized extends LoggerLayout {
|
||||
|
||||
/** Whether to include the event's location information (slow). */
|
||||
protected $locationInfo = false;
|
||||
|
||||
/** Sets the location information flag. */
|
||||
public function setLocationInfo($value) {
|
||||
$this->setBoolean('locationInfo', $value);
|
||||
}
|
||||
|
||||
/** Returns the location information flag. */
|
||||
public function getLocationInfo() {
|
||||
return $this->locationInfo;
|
||||
}
|
||||
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
// If required, initialize the location data
|
||||
if($this->locationInfo) {
|
||||
$event->getLocationInformation();
|
||||
}
|
||||
return serialize($event) . PHP_EOL;
|
||||
}
|
||||
}
|
56
sources/lib/Log4php/layouts/LoggerLayoutSimple.php
Normal file
56
sources/lib/Log4php/layouts/LoggerLayoutSimple.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* A simple layout.
|
||||
*
|
||||
* Returns the log statement in a format consisting of the
|
||||
* <b>level</b>, followed by " - " and then the <b>message</b>.
|
||||
*
|
||||
* For example the following php and properties files
|
||||
*
|
||||
* {@example ../../examples/php/layout_simple.php 19}<br>
|
||||
*
|
||||
* {@example ../../examples/resources/layout_simple.properties 18}<br>
|
||||
*
|
||||
* would result in:
|
||||
*
|
||||
* <samp>INFO - Hello World!</samp>
|
||||
*
|
||||
* @version $Revision: 1213283 $
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
*/
|
||||
class LoggerLayoutSimple extends LoggerLayout {
|
||||
/**
|
||||
* 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 LoggerLoggingEvent $event
|
||||
* @return string
|
||||
*/
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
$level = $event->getLevel();
|
||||
$message = $event->getRenderedMessage();
|
||||
return "$level - $message" . PHP_EOL;
|
||||
}
|
||||
}
|
201
sources/lib/Log4php/layouts/LoggerLayoutTTCC.php
Normal file
201
sources/lib/Log4php/layouts/LoggerLayoutTTCC.php
Normal file
@ -0,0 +1,201 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* TTCC layout format consists of <b>t</b>ime, <b>t</b>hread, <b>c</b>ategory and nested
|
||||
* diagnostic <b>c</b>ontext information, hence the name.
|
||||
*
|
||||
* <p>Each of the four fields can be individually enabled or
|
||||
* disabled. The time format depends on the <b>DateFormat</b> used.</p>
|
||||
*
|
||||
* <p>If no dateFormat is specified it defaults to '%c'.
|
||||
* See php {@link PHP_MANUAL#date} function for details.</p>
|
||||
*
|
||||
* Configurable parameters for this layout are:
|
||||
* - {@link $threadPrinting} (true|false) enable/disable pid reporting.
|
||||
* - {@link $categoryPrefixing} (true|false) enable/disable logger category reporting.
|
||||
* - {@link $contextPrinting} (true|false) enable/disable NDC reporting.
|
||||
* - {@link $microSecondsPrinting} (true|false) enable/disable micro seconds reporting in timestamp.
|
||||
* - {@link $dateFormat} (string) set date format. See php {@link PHP_MANUAL#date} function for details.
|
||||
*
|
||||
* An example how to use this layout:
|
||||
*
|
||||
* {@example ../../examples/php/layout_ttcc.php 19}<br>
|
||||
*
|
||||
* {@example ../../examples/resources/layout_ttcc.properties 18}<br>
|
||||
*
|
||||
* The above would print:<br>
|
||||
* <samp>02:28 [13714] INFO root - Hello World!</samp>
|
||||
*
|
||||
* @version $Revision: 1302503 $
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
*
|
||||
* @deprecated LoggerLayout TTCC is deprecated and will be removed in a future release. Please use
|
||||
* LoggerLayoutPattern instead.
|
||||
*/
|
||||
class LoggerLayoutTTCC extends LoggerLayout {
|
||||
|
||||
// Internal representation of options
|
||||
protected $threadPrinting = true;
|
||||
protected $categoryPrefixing = true;
|
||||
protected $contextPrinting = true;
|
||||
protected $microSecondsPrinting = true;
|
||||
|
||||
/**
|
||||
* @var string date format. See {@link PHP_MANUAL#strftime} for details
|
||||
*/
|
||||
protected $dateFormat = '%c';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string date format
|
||||
* @see dateFormat
|
||||
*/
|
||||
public function __construct($dateFormat = '') {
|
||||
$this->warn("LoggerLayout TTCC is deprecated and will be removed in a future release. Please use LoggerLayoutPattern instead.");
|
||||
if (!empty($dateFormat)) {
|
||||
$this->dateFormat = $dateFormat;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>ThreadPrinting</b> option specifies whether the name of the
|
||||
* current thread is part of log output or not. This is true by default.
|
||||
*/
|
||||
public function setThreadPrinting($threadPrinting) {
|
||||
$this->setBoolean('threadPrinting', $threadPrinting);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns value of the <b>ThreadPrinting</b> option.
|
||||
*/
|
||||
public function getThreadPrinting() {
|
||||
return $this->threadPrinting;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>CategoryPrefixing</b> option specifies whether {@link Category}
|
||||
* name is part of log output or not. This is true by default.
|
||||
*/
|
||||
public function setCategoryPrefixing($categoryPrefixing) {
|
||||
$this->setBoolean('categoryPrefixing', $categoryPrefixing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns value of the <b>CategoryPrefixing</b> option.
|
||||
*/
|
||||
public function getCategoryPrefixing() {
|
||||
return $this->categoryPrefixing;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>ContextPrinting</b> option specifies log output will include
|
||||
* the nested context information belonging to the current thread.
|
||||
* This is true by default.
|
||||
*/
|
||||
public function setContextPrinting($contextPrinting) {
|
||||
$this->setBoolean('contextPrinting', $contextPrinting);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns value of the <b>ContextPrinting</b> option.
|
||||
*/
|
||||
public function getContextPrinting() {
|
||||
return $this->contextPrinting;
|
||||
}
|
||||
|
||||
/**
|
||||
* The <b>MicroSecondsPrinting</b> option specifies if microseconds infos
|
||||
* should be printed at the end of timestamp.
|
||||
* This is true by default.
|
||||
*/
|
||||
public function setMicroSecondsPrinting($microSecondsPrinting) {
|
||||
$this->setBoolean('microSecondsPrinting', $microSecondsPrinting);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns value of the <b>MicroSecondsPrinting</b> option.
|
||||
*/
|
||||
public function getMicroSecondsPrinting() {
|
||||
return $this->microSecondsPrinting;
|
||||
}
|
||||
|
||||
|
||||
public function setDateFormat($dateFormat) {
|
||||
$this->setString('dateFormat', $dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDateFormat() {
|
||||
return $this->dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 LoggerLoggingEvent $event
|
||||
* @return string
|
||||
*/
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
$timeStamp = (float)$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 ignoresThrowable() {
|
||||
return true;
|
||||
}
|
||||
}
|
210
sources/lib/Log4php/layouts/LoggerLayoutXml.php
Normal file
210
sources/lib/Log4php/layouts/LoggerLayoutXml.php
Normal file
@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @package log4php
|
||||
*/
|
||||
|
||||
/**
|
||||
* The output of the LoggerXmlLayout consists of a series of log4php:event elements.
|
||||
*
|
||||
* Configurable parameters:
|
||||
* - {@link $locationInfo} - If set to true then the file name and line number
|
||||
* of the origin of the log statement will be included in output.
|
||||
* - {@link $log4jNamespace} - If set to true then log4j namespace will be used
|
||||
* instead of log4php namespace. This can be usefull when using log viewers
|
||||
* which can only parse the log4j namespace such as Apache Chainsaw.
|
||||
*
|
||||
* <p>It does not output a complete well-formed XML file.
|
||||
* The output is designed to be included as an external entity in a separate file to form
|
||||
* a correct XML file.</p>
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* {@example ../../examples/php/layout_xml.php 19}<br>
|
||||
*
|
||||
* {@example ../../examples/resources/layout_xml.properties 18}<br>
|
||||
*
|
||||
* The above would print:
|
||||
*
|
||||
* <pre>
|
||||
* <log4php:eventSet xmlns:log4php="http://logging.apache.org/log4php/" version="0.3" includesLocationInfo="true">
|
||||
* <log4php:event logger="root" level="INFO" thread="13802" timestamp="1252456226491">
|
||||
* <log4php:message><![CDATA[Hello World!]]></log4php:message>
|
||||
* <log4php:locationInfo class="main" file="examples/php/layout_xml.php" line="6" method="main" />
|
||||
* </log4php:event>
|
||||
* </log4php:eventSet>
|
||||
* </pre>
|
||||
*
|
||||
* @version $Revision: 1213283 $
|
||||
* @package log4php
|
||||
* @subpackage layouts
|
||||
*/
|
||||
class LoggerLayoutXml extends LoggerLayout {
|
||||
const LOG4J_NS_PREFIX ='log4j';
|
||||
const LOG4J_NS = 'http://jakarta.apache.org/log4j/';
|
||||
|
||||
const LOG4PHP_NS_PREFIX = 'log4php';
|
||||
const LOG4PHP_NS = 'http://logging.apache.org/log4php/';
|
||||
|
||||
const CDATA_START = '<![CDATA[';
|
||||
const CDATA_END = ']]>';
|
||||
const CDATA_PSEUDO_END = ']]>';
|
||||
const CDATA_EMBEDDED_END = ']]>]]><![CDATA[';
|
||||
|
||||
/**
|
||||
* If set to true then the file name and line number of the origin of the
|
||||
* log statement will be output.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $locationInfo = true;
|
||||
|
||||
/**
|
||||
* If set to true, log4j namespace will be used instead of the log4php
|
||||
* namespace.
|
||||
* @var boolean
|
||||
*/
|
||||
protected $log4jNamespace = false;
|
||||
|
||||
/** The namespace in use. */
|
||||
protected $namespace = self::LOG4PHP_NS;
|
||||
|
||||
/** The namespace prefix in use */
|
||||
protected $namespacePrefix = self::LOG4PHP_NS_PREFIX;
|
||||
|
||||
public function activateOptions() {
|
||||
if ($this->getLog4jNamespace()) {
|
||||
$this->namespace = self::LOG4J_NS;
|
||||
$this->namespacePrefix = self::LOG4J_NS_PREFIX;
|
||||
} else {
|
||||
$this->namespace = self::LOG4PHP_NS;
|
||||
$this->namespacePrefix = self::LOG4PHP_NS_PREFIX;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHeader() {
|
||||
return "<{$this->namespacePrefix}:eventSet ".
|
||||
"xmlns:{$this->namespacePrefix}=\"{$this->namespace}\" ".
|
||||
"version=\"0.3\" ".
|
||||
"includesLocationInfo=\"".($this->getLocationInfo() ? "true" : "false")."\"".
|
||||
">" . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a {@link LoggerLoggingEvent} in conformance with the log4php.dtd.
|
||||
*
|
||||
* @param LoggerLoggingEvent $event
|
||||
* @return string
|
||||
*/
|
||||
public function format(LoggerLoggingEvent $event) {
|
||||
$ns = $this->namespacePrefix;
|
||||
|
||||
$loggerName = $event->getLoggerName();
|
||||
$timeStamp = number_format((float)($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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFooter() {
|
||||
return "</{$this->namespacePrefix}:eventSet>" . PHP_EOL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Whether or not file name and line number will be included in the output.
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLocationInfo() {
|
||||
return $this->locationInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link $locationInfo} option takes a boolean value. By default,
|
||||
* it is set to false which means there will be no location
|
||||
* information output by this layout. If the the option is set to
|
||||
* true, then the file name and line number of the statement at the
|
||||
* origin of the log statement will be output.
|
||||
*/
|
||||
public function setLocationInfo($flag) {
|
||||
$this->setBoolean('locationInfo', $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
public function getLog4jNamespace() {
|
||||
return $this->log4jNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean
|
||||
*/
|
||||
public function setLog4jNamespace($flag) {
|
||||
$this->setBoolean('log4jNamespace', $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encases a string in CDATA tags, and escapes any existing CDATA end
|
||||
* tags already present in the string.
|
||||
* @param string $string
|
||||
*/
|
||||
private function encodeCDATA($string) {
|
||||
$string = str_replace(self::CDATA_END, self::CDATA_EMBEDDED_END, $string);
|
||||
return self::CDATA_START . $string . self::CDATA_END;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user