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:
131
sources/lib/Log4php/pattern/LoggerPatternConverter.php
Normal file
131
sources/lib/Log4php/pattern/LoggerPatternConverter.php
Normal file
@ -0,0 +1,131 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* LoggerPatternConverter is an abstract class that provides the formatting
|
||||
* functionality that derived classes need.
|
||||
*
|
||||
* <p>Conversion specifiers in a conversion patterns are parsed to
|
||||
* individual PatternConverters. Each of which is responsible for
|
||||
* converting a logging event in a converter specific manner.</p>
|
||||
*
|
||||
* @version $Revision: 1326626 $
|
||||
* @package log4php
|
||||
* @subpackage helpers
|
||||
* @since 0.3
|
||||
*/
|
||||
abstract class LoggerPatternConverter {
|
||||
|
||||
/**
|
||||
* Next converter in the converter chain.
|
||||
* @var LoggerPatternConverter
|
||||
*/
|
||||
public $next = null;
|
||||
|
||||
/**
|
||||
* Formatting information, parsed from pattern modifiers.
|
||||
* @var LoggerFormattingInfo
|
||||
*/
|
||||
protected $formattingInfo;
|
||||
|
||||
/**
|
||||
* Converter-specific formatting options.
|
||||
* @var array
|
||||
*/
|
||||
protected $option;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param LoggerFormattingInfo $formattingInfo
|
||||
* @param array $option
|
||||
*/
|
||||
public function __construct(LoggerFormattingInfo $formattingInfo = null, $option = null) {
|
||||
$this->formattingInfo = $formattingInfo;
|
||||
$this->option = $option;
|
||||
$this->activateOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called in constructor. Converters which need to process the options
|
||||
* can override this method.
|
||||
*/
|
||||
public function activateOptions() { }
|
||||
|
||||
/**
|
||||
* Converts the logging event to the desired format. Derived pattern
|
||||
* converters must implement this method.
|
||||
*
|
||||
* @param LoggerLoggingEvent $event
|
||||
*/
|
||||
abstract public function convert(LoggerLoggingEvent $event);
|
||||
|
||||
/**
|
||||
* Converts the event and formats it according to setting in the
|
||||
* Formatting information object.
|
||||
*
|
||||
* @param string &$sbuf string buffer to write to
|
||||
* @param LoggerLoggingEvent $event Event to be formatted.
|
||||
*/
|
||||
public function format(&$sbuf, $event) {
|
||||
$string = $this->convert($event);
|
||||
|
||||
if (!isset($this->formattingInfo)) {
|
||||
$sbuf .= $string;
|
||||
return;
|
||||
}
|
||||
|
||||
$fi = $this->formattingInfo;
|
||||
|
||||
// Empty string
|
||||
if($string === '' || is_null($string)) {
|
||||
if($fi->min > 0) {
|
||||
$sbuf .= str_repeat(' ', $fi->min);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$len = strlen($string);
|
||||
|
||||
// Trim the string if needed
|
||||
if($len > $fi->max) {
|
||||
if ($fi->trimLeft) {
|
||||
$sbuf .= substr($string, $len - $fi->max, $fi->max);
|
||||
} else {
|
||||
$sbuf .= substr($string , 0, $fi->max);
|
||||
}
|
||||
}
|
||||
|
||||
// Add padding if needed
|
||||
else if($len < $fi->min) {
|
||||
if($fi->padLeft) {
|
||||
$sbuf .= str_repeat(' ', $fi->min - $len);
|
||||
$sbuf .= $string;
|
||||
} else {
|
||||
$sbuf .= $string;
|
||||
$sbuf .= str_repeat(' ', $fi->min - $len);
|
||||
}
|
||||
}
|
||||
|
||||
// No action needed
|
||||
else {
|
||||
$sbuf .= $string;
|
||||
}
|
||||
}
|
||||
}
|
64
sources/lib/Log4php/pattern/LoggerPatternConverterClass.php
Normal file
64
sources/lib/Log4php/pattern/LoggerPatternConverterClass.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the fully qualified class name of the class from which the logging
|
||||
* request was issued.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterClass extends LoggerPatternConverter {
|
||||
|
||||
/** Length to which to shorten the class name. */
|
||||
private $length;
|
||||
|
||||
/** Holds processed class names. */
|
||||
private $cache = array();
|
||||
|
||||
public function activateOptions() {
|
||||
// Parse the option (desired output length)
|
||||
if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) {
|
||||
$this->length = (integer) $this->option;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
$name = $event->getLocationInformation()->getClassName();
|
||||
|
||||
if (!isset($this->cache[$name])) {
|
||||
|
||||
// If length is set return shortened class name
|
||||
if (isset($this->length)) {
|
||||
$this->cache[$name] = LoggerUtils::shortenClassName($name, $this->length);
|
||||
}
|
||||
|
||||
// If no length is specified return the full class name
|
||||
else {
|
||||
$this->cache[$name] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cache[$name];
|
||||
}
|
||||
}
|
||||
|
35
sources/lib/Log4php/pattern/LoggerPatternConverterCookie.php
Normal file
35
sources/lib/Log4php/pattern/LoggerPatternConverterCookie.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from the $_COOKIE superglobal array corresponding to the
|
||||
* given key. If no key is given, return all values.
|
||||
*
|
||||
* Options:
|
||||
* [0] $_COOKIE key value
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterCookie extends LoggerPatternConverterSuperglobal {
|
||||
protected $name = '_COOKIE';
|
||||
}
|
91
sources/lib/Log4php/pattern/LoggerPatternConverterDate.php
Normal file
91
sources/lib/Log4php/pattern/LoggerPatternConverterDate.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the date/time of the logging request.
|
||||
*
|
||||
* Option: the datetime format, as used by the date() function. If
|
||||
* the option is not given, the default format 'c' will be used.
|
||||
*
|
||||
* There are several "special" values which can be given for this option:
|
||||
* 'ISO8601', 'ABSOLUTE' and 'DATE'.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterDate extends LoggerPatternConverter {
|
||||
|
||||
const DATE_FORMAT_ISO8601 = 'c';
|
||||
|
||||
const DATE_FORMAT_ABSOLUTE = 'H:i:s';
|
||||
|
||||
const DATE_FORMAT_DATE = 'd M Y H:i:s.u';
|
||||
|
||||
private $format = self::DATE_FORMAT_ISO8601;
|
||||
|
||||
private $specials = array(
|
||||
'ISO8601' => self::DATE_FORMAT_ISO8601,
|
||||
'ABSOLUTE' => self::DATE_FORMAT_ABSOLUTE,
|
||||
'DATE' => self::DATE_FORMAT_DATE,
|
||||
);
|
||||
|
||||
private $useLocalDate = false;
|
||||
|
||||
public function activateOptions() {
|
||||
|
||||
// Parse the option (date format)
|
||||
if (!empty($this->option)) {
|
||||
if(isset($this->specials[$this->option])) {
|
||||
$this->format = $this->specials[$this->option];
|
||||
} else {
|
||||
$this->format = $this->option;
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether the pattern contains milliseconds (u)
|
||||
if (preg_match('/(?<!\\\\)u/', $this->format)) {
|
||||
$this->useLocalDate = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
if ($this->useLocalDate) {
|
||||
return $this->date($this->format, $event->getTimeStamp());
|
||||
}
|
||||
return date($this->format, $event->getTimeStamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently, PHP date() function always returns zeros for milliseconds (u)
|
||||
* on Windows. This is a replacement function for date() which correctly
|
||||
* displays milliseconds on all platforms.
|
||||
*
|
||||
* It is slower than PHP date() so it should only be used if necessary.
|
||||
*/
|
||||
private function date($format, $utimestamp) {
|
||||
$timestamp = floor($utimestamp);
|
||||
$ms = floor(($utimestamp - $timestamp) * 1000);
|
||||
$ms = str_pad($ms, 3, '0', STR_PAD_LEFT);
|
||||
|
||||
return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from the $_ENV superglobal array corresponding to the
|
||||
* given key.
|
||||
*
|
||||
* Options:
|
||||
* [0] $_ENV key value
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterEnvironment extends LoggerPatternConverterSuperglobal {
|
||||
protected $name = '_ENV';
|
||||
}
|
34
sources/lib/Log4php/pattern/LoggerPatternConverterFile.php
Normal file
34
sources/lib/Log4php/pattern/LoggerPatternConverterFile.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the name of the file from which the logging request was issued.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterFile extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getLocationInformation()->getFileName();
|
||||
}
|
||||
}
|
34
sources/lib/Log4php/pattern/LoggerPatternConverterLevel.php
Normal file
34
sources/lib/Log4php/pattern/LoggerPatternConverterLevel.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the event's level.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterLevel extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getLevel()->toString();
|
||||
}
|
||||
}
|
35
sources/lib/Log4php/pattern/LoggerPatternConverterLine.php
Normal file
35
sources/lib/Log4php/pattern/LoggerPatternConverterLine.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the line number within the file from which the logging request was
|
||||
* issued.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterLine extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getLocationInformation()->getLineNumber();
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the literal value passed in the constructor, without modifications.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterLiteral extends LoggerPatternConverter {
|
||||
|
||||
private $literalValue;
|
||||
|
||||
public function __construct($literalValue) {
|
||||
$this->literalValue = $literalValue;
|
||||
}
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $this->literalValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the line number within the file from which the logging request was
|
||||
* issued.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterLocation extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return
|
||||
$event->getLocationInformation()->getClassName() . '.' .
|
||||
$event->getLocationInformation()->getMethodName() . '(' .
|
||||
$event->getLocationInformation()->getFileName() . ':' .
|
||||
$event->getLocationInformation()->getLineNumber() . ')';
|
||||
}
|
||||
}
|
65
sources/lib/Log4php/pattern/LoggerPatternConverterLogger.php
Normal file
65
sources/lib/Log4php/pattern/LoggerPatternConverterLogger.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the name of the logger which created the logging request.
|
||||
*
|
||||
* Takes one option, which is an integer. If the option is given, the logger
|
||||
* name will be shortened to the given length, if possible.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterLogger extends LoggerPatternConverter {
|
||||
|
||||
/** Length to which to shorten the name. */
|
||||
private $length;
|
||||
|
||||
/** Holds processed logger names. */
|
||||
private $cache = array();
|
||||
|
||||
public function activateOptions() {
|
||||
// Parse the option (desired output length)
|
||||
if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) {
|
||||
$this->length = (integer) $this->option;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(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] = LoggerUtils::shortenClassName($name, $this->length);
|
||||
}
|
||||
|
||||
// If no length is specified return full logger name
|
||||
else {
|
||||
$this->cache[$name] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->cache[$name];
|
||||
}
|
||||
}
|
55
sources/lib/Log4php/pattern/LoggerPatternConverterMDC.php
Normal file
55
sources/lib/Log4php/pattern/LoggerPatternConverterMDC.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the Mapped Diagnostic Context value corresponding to the given key.
|
||||
*
|
||||
* Options:
|
||||
* [0] the MDC key
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterMDC extends LoggerPatternConverter {
|
||||
|
||||
private $key;
|
||||
|
||||
public function activateOptions() {
|
||||
if (isset($this->option) && $this->option !== '') {
|
||||
$this->key = $this->option;
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the logged message.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterMessage extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getRenderedMessage();
|
||||
}
|
||||
}
|
35
sources/lib/Log4php/pattern/LoggerPatternConverterMethod.php
Normal file
35
sources/lib/Log4php/pattern/LoggerPatternConverterMethod.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the name of the function or method from which the logging request
|
||||
* was issued.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterMethod extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getLocationInformation()->getMethodName();
|
||||
}
|
||||
}
|
35
sources/lib/Log4php/pattern/LoggerPatternConverterNDC.php
Normal file
35
sources/lib/Log4php/pattern/LoggerPatternConverterNDC.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the full Nested Diagnostic Context.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterNDC extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $event->getNDC();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns platform-specific newline character(s).
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterNewLine extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return PHP_EOL;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the PID of the current process.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterProcess extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return getmypid();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the number of milliseconds elapsed since the start of the
|
||||
* application until the creation of the logging event.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1379731 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterRelative extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
$ts = $event->getRelativeTime();
|
||||
return number_format($ts, 4);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from the $_REQUEST superglobal array corresponding to the
|
||||
* given key.
|
||||
*
|
||||
* Options:
|
||||
* [0] $_REQUEST key value
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterRequest extends LoggerPatternConverterSuperglobal {
|
||||
protected $name = '_REQUEST';
|
||||
}
|
35
sources/lib/Log4php/pattern/LoggerPatternConverterServer.php
Normal file
35
sources/lib/Log4php/pattern/LoggerPatternConverterServer.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from the $_SERVER superglobal array corresponding to the
|
||||
* given key.
|
||||
*
|
||||
* Options:
|
||||
* [0] $_SERVER key value
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterServer extends LoggerPatternConverterSuperglobal {
|
||||
protected $name = '_SERVER';
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from the $_SESSION superglobal array corresponding to the
|
||||
* given key.
|
||||
*
|
||||
* Options:
|
||||
* [0] $_SESSION key value
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterSession extends LoggerPatternConverterSuperglobal {
|
||||
protected $name = '_SESSION';
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the active session ID, or an empty string if out of session.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterSessionID extends LoggerPatternConverter {
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return session_id();
|
||||
}
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a value from a superglobal array corresponding to the
|
||||
* given key.
|
||||
*
|
||||
* Option: the key to look up within the superglobal array
|
||||
*
|
||||
* Also, it is possible that a superglobal variable is not populated by PHP
|
||||
* because of the settings in the variables-order ini directive. In this case
|
||||
* the converter will return an empty value.
|
||||
*
|
||||
* @see http://php.net/manual/en/language.variables.superglobals.php
|
||||
* @see http://www.php.net/manual/en/ini.core.php#ini.variables-order
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1326626 $
|
||||
* @since 2.3
|
||||
*/
|
||||
abstract class LoggerPatternConverterSuperglobal extends LoggerPatternConverter {
|
||||
|
||||
/**
|
||||
* Name of the superglobal variable, to be defined by subclasses.
|
||||
* For example: "_SERVER" or "_ENV".
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
protected $value = '';
|
||||
|
||||
public function activateOptions() {
|
||||
// Read the key from options array
|
||||
if (isset($this->option) && $this->option !== '') {
|
||||
$key = $this->option;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is a bug in PHP which doesn't allow superglobals to be
|
||||
* accessed when their name is stored in a variable, e.g.:
|
||||
*
|
||||
* $name = '_SERVER';
|
||||
* $array = $$name;
|
||||
*
|
||||
* This code does not work when run from within a method (only when run
|
||||
* in global scope). But the following code does work:
|
||||
*
|
||||
* $name = '_SERVER';
|
||||
* global $$name;
|
||||
* $array = $$name;
|
||||
*
|
||||
* That's why global is used here.
|
||||
*/
|
||||
global ${$this->name};
|
||||
|
||||
// Check the given superglobal exists. It is possible that it is not initialized.
|
||||
if (!isset(${$this->name})) {
|
||||
$class = get_class($this);
|
||||
trigger_error("log4php: $class: Cannot find superglobal variable \${$this->name}.", E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
$source = ${$this->name};
|
||||
|
||||
// When the key is set, display the matching value
|
||||
if (isset($key)) {
|
||||
if (isset($source[$key])) {
|
||||
$this->value = $source[$key];
|
||||
}
|
||||
}
|
||||
|
||||
// When the key is not set, display all values
|
||||
else {
|
||||
$values = array();
|
||||
foreach($source as $key => $value) {
|
||||
$values[] = "$key=$value";
|
||||
}
|
||||
$this->value = implode(', ', $values);
|
||||
}
|
||||
}
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
return $this->value;
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
<?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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the throwable information linked to the logging event, if any.
|
||||
*
|
||||
* @package log4php
|
||||
* @subpackage pattern
|
||||
* @version $Revision: 1395470 $
|
||||
* @since 2.3
|
||||
*/
|
||||
class LoggerPatternConverterThrowable extends LoggerPatternConverter {
|
||||
|
||||
public function convert(LoggerLoggingEvent $event) {
|
||||
$info = $event->getThrowableInformation();
|
||||
if (isset($info)) {
|
||||
$ex = $info->getThrowable();
|
||||
return (string) $ex . PHP_EOL;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user