@@ -35,17 +35,17 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class Payone_Log4php_LoggerAppenderNull extends Payone_Log4php_LoggerAppender { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * This appender does not require a layout. |
|
| 40 | - */ |
|
| 41 | - protected $requiresLayout = false; |
|
| 38 | + /** |
|
| 39 | + * This appender does not require a layout. |
|
| 40 | + */ |
|
| 41 | + protected $requiresLayout = false; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Do nothing. |
|
| 45 | - * |
|
| 46 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 47 | - */ |
|
| 48 | - public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * Do nothing. |
|
| 45 | + * |
|
| 46 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 47 | + */ |
|
| 48 | + public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | |
@@ -49,70 +49,70 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class Payone_Log4php_LoggerMDC { |
| 51 | 51 | |
| 52 | - /** Holds the context map. */ |
|
| 53 | - private static $map = array(); |
|
| 52 | + /** Holds the context map. */ |
|
| 53 | + private static $map = array(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Stores a context value as identified with the key parameter into the |
|
| 57 | - * context map. |
|
| 58 | - * |
|
| 59 | - * @param string $key the key |
|
| 60 | - * @param string $value the value |
|
| 61 | - */ |
|
| 62 | - public static function put($key, $value) { |
|
| 63 | - self::$map[$key] = $value; |
|
| 64 | - } |
|
| 55 | + /** |
|
| 56 | + * Stores a context value as identified with the key parameter into the |
|
| 57 | + * context map. |
|
| 58 | + * |
|
| 59 | + * @param string $key the key |
|
| 60 | + * @param string $value the value |
|
| 61 | + */ |
|
| 62 | + public static function put($key, $value) { |
|
| 63 | + self::$map[$key] = $value; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Returns the context value identified by the key parameter. |
|
| 68 | - * |
|
| 69 | - * Special key identifiers can be used to map values in the global $_SERVER |
|
| 70 | - * and $_ENV vars. To access them, use 'server.' or 'env.' followed by the |
|
| 71 | - * desired var name as the key. |
|
| 72 | - * |
|
| 73 | - * @param string $key The key. |
|
| 74 | - * @return string The context or an empty string if no context found |
|
| 75 | - * for given key. |
|
| 76 | - */ |
|
| 77 | - public static function get($key) { |
|
| 78 | - if(!empty($key)) { |
|
| 79 | - if(strpos($key, 'server.') === 0) { |
|
| 80 | - $varName = substr($key, 7); |
|
| 81 | - return isset($_SERVER[$varName]) ? $_SERVER[$varName] : ''; |
|
| 82 | - } else if(strpos($key, 'env.') === 0) { |
|
| 83 | - $varName = substr($key, 4); |
|
| 84 | - $value = getenv($varName); |
|
| 85 | - return ($value !== false) ? $value : ''; |
|
| 86 | - } else { |
|
| 87 | - return isset(self::$map[$key]) ? self::$map[$key] : ''; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - return ''; |
|
| 91 | - } |
|
| 66 | + /** |
|
| 67 | + * Returns the context value identified by the key parameter. |
|
| 68 | + * |
|
| 69 | + * Special key identifiers can be used to map values in the global $_SERVER |
|
| 70 | + * and $_ENV vars. To access them, use 'server.' or 'env.' followed by the |
|
| 71 | + * desired var name as the key. |
|
| 72 | + * |
|
| 73 | + * @param string $key The key. |
|
| 74 | + * @return string The context or an empty string if no context found |
|
| 75 | + * for given key. |
|
| 76 | + */ |
|
| 77 | + public static function get($key) { |
|
| 78 | + if(!empty($key)) { |
|
| 79 | + if(strpos($key, 'server.') === 0) { |
|
| 80 | + $varName = substr($key, 7); |
|
| 81 | + return isset($_SERVER[$varName]) ? $_SERVER[$varName] : ''; |
|
| 82 | + } else if(strpos($key, 'env.') === 0) { |
|
| 83 | + $varName = substr($key, 4); |
|
| 84 | + $value = getenv($varName); |
|
| 85 | + return ($value !== false) ? $value : ''; |
|
| 86 | + } else { |
|
| 87 | + return isset(self::$map[$key]) ? self::$map[$key] : ''; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + return ''; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns the contex map as an array. |
|
| 95 | - * @return array The MDC context map. |
|
| 96 | - */ |
|
| 97 | - public static function getMap() { |
|
| 98 | - return self::$map; |
|
| 99 | - } |
|
| 93 | + /** |
|
| 94 | + * Returns the contex map as an array. |
|
| 95 | + * @return array The MDC context map. |
|
| 96 | + */ |
|
| 97 | + public static function getMap() { |
|
| 98 | + return self::$map; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Removes the the context identified by the key parameter. |
|
| 103 | - * |
|
| 104 | - * Only affects user mappings, not $_ENV or $_SERVER. |
|
| 105 | - * |
|
| 106 | - * @param string $key The key to be removed. |
|
| 107 | - */ |
|
| 108 | - public static function remove($key) { |
|
| 109 | - unset(self::$map[$key]); |
|
| 110 | - } |
|
| 101 | + /** |
|
| 102 | + * Removes the the context identified by the key parameter. |
|
| 103 | + * |
|
| 104 | + * Only affects user mappings, not $_ENV or $_SERVER. |
|
| 105 | + * |
|
| 106 | + * @param string $key The key to be removed. |
|
| 107 | + */ |
|
| 108 | + public static function remove($key) { |
|
| 109 | + unset(self::$map[$key]); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Clears the mapped diagnostic context. |
|
| 114 | - */ |
|
| 115 | - public static function clear() { |
|
| 116 | - self::$map = array(); |
|
| 117 | - } |
|
| 112 | + /** |
|
| 113 | + * Clears the mapped diagnostic context. |
|
| 114 | + */ |
|
| 115 | + public static function clear() { |
|
| 116 | + self::$map = array(); |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -75,11 +75,11 @@ |
||
| 75 | 75 | * for given key. |
| 76 | 76 | */ |
| 77 | 77 | public static function get($key) { |
| 78 | - if(!empty($key)) { |
|
| 79 | - if(strpos($key, 'server.') === 0) { |
|
| 78 | + if (!empty($key)) { |
|
| 79 | + if (strpos($key, 'server.') === 0) { |
|
| 80 | 80 | $varName = substr($key, 7); |
| 81 | 81 | return isset($_SERVER[$varName]) ? $_SERVER[$varName] : ''; |
| 82 | - } else if(strpos($key, 'env.') === 0) { |
|
| 82 | + } else if (strpos($key, 'env.') === 0) { |
|
| 83 | 83 | $varName = substr($key, 4); |
| 84 | 84 | $value = getenv($varName); |
| 85 | 85 | return ($value !== false) ? $value : ''; |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Payone_Log4php_LoggerPatternConverterProcess extends Payone_Log4php_LoggerPatternConverter { |
| 28 | 28 | |
| 29 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | - return getmypid(); |
|
| 31 | - } |
|
| 29 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | + return getmypid(); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -27,128 +27,128 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Payone_Log4php_LoggerLayoutPattern extends Payone_Log4php_LoggerLayout { |
| 29 | 29 | |
| 30 | - /** Default conversion pattern */ |
|
| 31 | - const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
| 30 | + /** Default conversion pattern */ |
|
| 31 | + const DEFAULT_CONVERSION_PATTERN = '%m%n'; |
|
| 32 | 32 | |
| 33 | - /** Default conversion TTCC Pattern */ |
|
| 34 | - const TTCC_CONVERSION_PATTERN = '%d [%t] %p %c %x - %m%n'; |
|
| 33 | + /** Default conversion TTCC Pattern */ |
|
| 34 | + const TTCC_CONVERSION_PATTERN = '%d [%t] %p %c %x - %m%n'; |
|
| 35 | 35 | |
| 36 | - /** The conversion pattern. */ |
|
| 37 | - protected $pattern = self::DEFAULT_CONVERSION_PATTERN; |
|
| 36 | + /** The conversion pattern. */ |
|
| 37 | + protected $pattern = self::DEFAULT_CONVERSION_PATTERN; |
|
| 38 | 38 | |
| 39 | - /** Maps conversion keywords to the relevant converter. */ |
|
| 40 | - protected static $defaultConverterMap = array( |
|
| 41 | - 'c' => 'LoggerPatternConverterLogger', |
|
| 42 | - 'lo' => 'LoggerPatternConverterLogger', |
|
| 43 | - 'logger' => 'LoggerPatternConverterLogger', |
|
| 39 | + /** Maps conversion keywords to the relevant converter. */ |
|
| 40 | + protected static $defaultConverterMap = array( |
|
| 41 | + 'c' => 'LoggerPatternConverterLogger', |
|
| 42 | + 'lo' => 'LoggerPatternConverterLogger', |
|
| 43 | + 'logger' => 'LoggerPatternConverterLogger', |
|
| 44 | 44 | |
| 45 | - 'C' => 'LoggerPatternConverterClass', |
|
| 46 | - 'class' => 'LoggerPatternConverterClass', |
|
| 45 | + 'C' => 'LoggerPatternConverterClass', |
|
| 46 | + 'class' => 'LoggerPatternConverterClass', |
|
| 47 | 47 | |
| 48 | - 'cookie' => 'LoggerPatternConverterCookie', |
|
| 48 | + 'cookie' => 'LoggerPatternConverterCookie', |
|
| 49 | 49 | |
| 50 | - 'd' => 'LoggerPatternConverterDate', |
|
| 51 | - 'date' => 'LoggerPatternConverterDate', |
|
| 50 | + 'd' => 'LoggerPatternConverterDate', |
|
| 51 | + 'date' => 'LoggerPatternConverterDate', |
|
| 52 | 52 | |
| 53 | - 'e' => 'LoggerPatternConverterEnvironment', |
|
| 54 | - 'env' => 'LoggerPatternConverterEnvironment', |
|
| 53 | + 'e' => 'LoggerPatternConverterEnvironment', |
|
| 54 | + 'env' => 'LoggerPatternConverterEnvironment', |
|
| 55 | 55 | |
| 56 | - 'ex' => 'LoggerPatternConverterThrowable', |
|
| 57 | - 'throwable' => 'LoggerPatternConverterThrowable', |
|
| 56 | + 'ex' => 'LoggerPatternConverterThrowable', |
|
| 57 | + 'throwable' => 'LoggerPatternConverterThrowable', |
|
| 58 | 58 | |
| 59 | - 'F' => 'LoggerPatternConverterFile', |
|
| 60 | - 'file' => 'LoggerPatternConverterFile', |
|
| 59 | + 'F' => 'LoggerPatternConverterFile', |
|
| 60 | + 'file' => 'LoggerPatternConverterFile', |
|
| 61 | 61 | |
| 62 | - 'L' => 'LoggerPatternConverterLine', |
|
| 63 | - 'line' => 'LoggerPatternConverterLine', |
|
| 62 | + 'L' => 'LoggerPatternConverterLine', |
|
| 63 | + 'line' => 'LoggerPatternConverterLine', |
|
| 64 | 64 | |
| 65 | - 'm' => 'LoggerPatternConverterMessage', |
|
| 66 | - 'msg' => 'LoggerPatternConverterMessage', |
|
| 67 | - 'message' => 'LoggerPatternConverterMessage', |
|
| 65 | + 'm' => 'LoggerPatternConverterMessage', |
|
| 66 | + 'msg' => 'LoggerPatternConverterMessage', |
|
| 67 | + 'message' => 'LoggerPatternConverterMessage', |
|
| 68 | 68 | |
| 69 | - 'M' => 'LoggerPatternConverterMethod', |
|
| 70 | - 'method' => 'LoggerPatternConverterMethod', |
|
| 69 | + 'M' => 'LoggerPatternConverterMethod', |
|
| 70 | + 'method' => 'LoggerPatternConverterMethod', |
|
| 71 | 71 | |
| 72 | - 'n' => 'LoggerPatternConverterNewLine', |
|
| 73 | - 'newline' => 'LoggerPatternConverterNewLine', |
|
| 72 | + 'n' => 'LoggerPatternConverterNewLine', |
|
| 73 | + 'newline' => 'LoggerPatternConverterNewLine', |
|
| 74 | 74 | |
| 75 | - 'p' => 'LoggerPatternConverterLevel', |
|
| 76 | - 'le' => 'LoggerPatternConverterLevel', |
|
| 77 | - 'level' => 'LoggerPatternConverterLevel', |
|
| 75 | + 'p' => 'LoggerPatternConverterLevel', |
|
| 76 | + 'le' => 'LoggerPatternConverterLevel', |
|
| 77 | + 'level' => 'LoggerPatternConverterLevel', |
|
| 78 | 78 | |
| 79 | - 'r' => 'LoggerPatternConverterRelative', |
|
| 80 | - 'relative' => 'LoggerPatternConverterRelative', |
|
| 79 | + 'r' => 'LoggerPatternConverterRelative', |
|
| 80 | + 'relative' => 'LoggerPatternConverterRelative', |
|
| 81 | 81 | |
| 82 | - 'req' => 'LoggerPatternConverterRequest', |
|
| 83 | - 'request' => 'LoggerPatternConverterRequest', |
|
| 82 | + 'req' => 'LoggerPatternConverterRequest', |
|
| 83 | + 'request' => 'LoggerPatternConverterRequest', |
|
| 84 | 84 | |
| 85 | - 's' => 'LoggerPatternConverterServer', |
|
| 86 | - 'server' => 'LoggerPatternConverterServer', |
|
| 85 | + 's' => 'LoggerPatternConverterServer', |
|
| 86 | + 'server' => 'LoggerPatternConverterServer', |
|
| 87 | 87 | |
| 88 | - 'ses' => 'LoggerPatternConverterSession', |
|
| 89 | - 'session' => 'LoggerPatternConverterSession', |
|
| 88 | + 'ses' => 'LoggerPatternConverterSession', |
|
| 89 | + 'session' => 'LoggerPatternConverterSession', |
|
| 90 | 90 | |
| 91 | - 'sid' => 'LoggerPatternConverterSessionID', |
|
| 92 | - 'sessionid' => 'LoggerPatternConverterSessionID', |
|
| 91 | + 'sid' => 'LoggerPatternConverterSessionID', |
|
| 92 | + 'sessionid' => 'LoggerPatternConverterSessionID', |
|
| 93 | 93 | |
| 94 | - 't' => 'LoggerPatternConverterProcess', |
|
| 95 | - 'pid' => 'LoggerPatternConverterProcess', |
|
| 96 | - 'process' => 'LoggerPatternConverterProcess', |
|
| 94 | + 't' => 'LoggerPatternConverterProcess', |
|
| 95 | + 'pid' => 'LoggerPatternConverterProcess', |
|
| 96 | + 'process' => 'LoggerPatternConverterProcess', |
|
| 97 | 97 | |
| 98 | - 'x' => 'LoggerPatternConverterNDC', |
|
| 99 | - 'ndc' => 'LoggerPatternConverterNDC', |
|
| 98 | + 'x' => 'LoggerPatternConverterNDC', |
|
| 99 | + 'ndc' => 'LoggerPatternConverterNDC', |
|
| 100 | 100 | |
| 101 | - 'X' => 'LoggerPatternConverterMDC', |
|
| 102 | - 'mdc' => 'LoggerPatternConverterMDC', |
|
| 103 | - ); |
|
| 101 | + 'X' => 'LoggerPatternConverterMDC', |
|
| 102 | + 'mdc' => 'LoggerPatternConverterMDC', |
|
| 103 | + ); |
|
| 104 | 104 | |
| 105 | - protected $converterMap = array(); |
|
| 105 | + protected $converterMap = array(); |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Head of a chain of Converters. |
|
| 109 | - * @var Payone_Log4php_LoggerPatternConverter |
|
| 110 | - */ |
|
| 111 | - private $head; |
|
| 107 | + /** |
|
| 108 | + * Head of a chain of Converters. |
|
| 109 | + * @var Payone_Log4php_LoggerPatternConverter |
|
| 110 | + */ |
|
| 111 | + private $head; |
|
| 112 | 112 | |
| 113 | - public static function getDefaultConverterMap() { |
|
| 114 | - return self::$defaultConverterMap; |
|
| 115 | - } |
|
| 113 | + public static function getDefaultConverterMap() { |
|
| 114 | + return self::$defaultConverterMap; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function __construct() { |
|
| 118 | - $this->converterMap = self::$defaultConverterMap; |
|
| 119 | - } |
|
| 117 | + public function __construct() { |
|
| 118 | + $this->converterMap = self::$defaultConverterMap; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Set the <b>ConversionPattern</b> option. This is the string which |
|
| 123 | - * controls formatting and consists of a mix of literal content and |
|
| 124 | - * conversion specifiers. |
|
| 125 | - */ |
|
| 126 | - public function setConversionPattern($conversionPattern) { |
|
| 127 | - $this->pattern = $conversionPattern; |
|
| 128 | - } |
|
| 121 | + /** |
|
| 122 | + * Set the <b>ConversionPattern</b> option. This is the string which |
|
| 123 | + * controls formatting and consists of a mix of literal content and |
|
| 124 | + * conversion specifiers. |
|
| 125 | + */ |
|
| 126 | + public function setConversionPattern($conversionPattern) { |
|
| 127 | + $this->pattern = $conversionPattern; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - public function activateOptions() { |
|
| 131 | - if (!isset($this->pattern)) { |
|
| 132 | - throw new Payone_Log4php_LoggerException("Mandatory parameter 'conversionPattern' is not set."); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - $parser = new Payone_Log4php_LoggerPatternParser($this->pattern, $this->converterMap); |
|
| 136 | - $this->head = $parser->parse(); |
|
| 137 | - } |
|
| 130 | + public function activateOptions() { |
|
| 131 | + if (!isset($this->pattern)) { |
|
| 132 | + throw new Payone_Log4php_LoggerException("Mandatory parameter 'conversionPattern' is not set."); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + $parser = new Payone_Log4php_LoggerPatternParser($this->pattern, $this->converterMap); |
|
| 136 | + $this->head = $parser->parse(); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Produces a formatted string as specified by the conversion pattern. |
|
| 141 | - * |
|
| 142 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 143 | - * @return string |
|
| 144 | - */ |
|
| 145 | - public function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 146 | - $sbuf = ''; |
|
| 147 | - $converter = $this->head; |
|
| 148 | - while ($converter !== null) { |
|
| 149 | - $converter->format($sbuf, $event); |
|
| 150 | - $converter = $converter->next; |
|
| 151 | - } |
|
| 152 | - return $sbuf; |
|
| 153 | - } |
|
| 139 | + /** |
|
| 140 | + * Produces a formatted string as specified by the conversion pattern. |
|
| 141 | + * |
|
| 142 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 143 | + * @return string |
|
| 144 | + */ |
|
| 145 | + public function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 146 | + $sbuf = ''; |
|
| 147 | + $converter = $this->head; |
|
| 148 | + while ($converter !== null) { |
|
| 149 | + $converter->format($sbuf, $event); |
|
| 150 | + $converter = $converter->next; |
|
| 151 | + } |
|
| 152 | + return $sbuf; |
|
| 153 | + } |
|
| 154 | 154 | } |
| 155 | 155 | \ No newline at end of file |
@@ -26,262 +26,262 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | abstract class Payone_Log4php_LoggerAppender extends Payone_Log4php_LoggerConfigurable { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Set to true when the appender is closed. A closed appender will not |
|
| 31 | - * accept any logging requests. |
|
| 32 | - * @var boolean |
|
| 33 | - */ |
|
| 34 | - protected $closed = false; |
|
| 29 | + /** |
|
| 30 | + * Set to true when the appender is closed. A closed appender will not |
|
| 31 | + * accept any logging requests. |
|
| 32 | + * @var boolean |
|
| 33 | + */ |
|
| 34 | + protected $closed = false; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * The first filter in the filter chain. |
|
| 38 | - * @var LoggerFilter |
|
| 39 | - */ |
|
| 40 | - protected $filter; |
|
| 36 | + /** |
|
| 37 | + * The first filter in the filter chain. |
|
| 38 | + * @var LoggerFilter |
|
| 39 | + */ |
|
| 40 | + protected $filter; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * The appender's layout. Can be null if the appender does not use |
|
| 44 | - * a layout. |
|
| 45 | - * @var Payone_Log4php_LoggerLayout |
|
| 46 | - */ |
|
| 47 | - protected $layout; |
|
| 42 | + /** |
|
| 43 | + * The appender's layout. Can be null if the appender does not use |
|
| 44 | + * a layout. |
|
| 45 | + * @var Payone_Log4php_LoggerLayout |
|
| 46 | + */ |
|
| 47 | + protected $layout; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Appender name. Used by other components to identify this appender. |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $name; |
|
| 49 | + /** |
|
| 50 | + * Appender name. Used by other components to identify this appender. |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $name; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Appender threshold level. Events whose level is below the threshold |
|
| 57 | - * will not be logged. |
|
| 58 | - * @var Payone_Log4php_LoggerLevel |
|
| 59 | - */ |
|
| 60 | - protected $threshold; |
|
| 55 | + /** |
|
| 56 | + * Appender threshold level. Events whose level is below the threshold |
|
| 57 | + * will not be logged. |
|
| 58 | + * @var Payone_Log4php_LoggerLevel |
|
| 59 | + */ |
|
| 60 | + protected $threshold; |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Set to true if the appender requires a layout. |
|
| 64 | - * |
|
| 65 | - * True by default, appenders which do not use a layout should override |
|
| 66 | - * this property to false. |
|
| 67 | - * |
|
| 68 | - * @var boolean |
|
| 69 | - */ |
|
| 70 | - protected $requiresLayout = true; |
|
| 62 | + /** |
|
| 63 | + * Set to true if the appender requires a layout. |
|
| 64 | + * |
|
| 65 | + * True by default, appenders which do not use a layout should override |
|
| 66 | + * this property to false. |
|
| 67 | + * |
|
| 68 | + * @var boolean |
|
| 69 | + */ |
|
| 70 | + protected $requiresLayout = true; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Default constructor. |
|
| 74 | - * @param string $name Appender name |
|
| 75 | - */ |
|
| 76 | - public function __construct($name = '') { |
|
| 77 | - $this->name = $name; |
|
| 72 | + /** |
|
| 73 | + * Default constructor. |
|
| 74 | + * @param string $name Appender name |
|
| 75 | + */ |
|
| 76 | + public function __construct($name = '') { |
|
| 77 | + $this->name = $name; |
|
| 78 | 78 | |
| 79 | - // Closes the appender on shutdown. Better than a destructor because |
|
| 80 | - // it will be called even if a fatal error occurs (destructor won't). |
|
| 81 | - register_shutdown_function(array($this, 'close')); |
|
| 79 | + // Closes the appender on shutdown. Better than a destructor because |
|
| 80 | + // it will be called even if a fatal error occurs (destructor won't). |
|
| 81 | + register_shutdown_function(array($this, 'close')); |
|
| 82 | 82 | |
| 83 | - if ($this->requiresLayout) { |
|
| 84 | - $this->layout = $this->getDefaultLayout(); |
|
| 85 | - } |
|
| 86 | - } |
|
| 83 | + if ($this->requiresLayout) { |
|
| 84 | + $this->layout = $this->getDefaultLayout(); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Returns the default layout for this appender. Can be overriden by |
|
| 90 | - * derived appenders. |
|
| 91 | - * |
|
| 92 | - * @return Payone_Log4php_LoggerLayout |
|
| 93 | - */ |
|
| 94 | - public function getDefaultLayout() |
|
| 95 | - { |
|
| 96 | - return new Payone_Log4php_LoggerLayoutSimple(); |
|
| 97 | - } |
|
| 88 | + /** |
|
| 89 | + * Returns the default layout for this appender. Can be overriden by |
|
| 90 | + * derived appenders. |
|
| 91 | + * |
|
| 92 | + * @return Payone_Log4php_LoggerLayout |
|
| 93 | + */ |
|
| 94 | + public function getDefaultLayout() |
|
| 95 | + { |
|
| 96 | + return new Payone_Log4php_LoggerLayoutSimple(); |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Adds a filter to the end of the filter chain. |
|
| 101 | - * @param LoggerFilter $filter add a new LoggerFilter |
|
| 102 | - */ |
|
| 103 | - public function addFilter($filter) { |
|
| 104 | - if($this->filter === null) { |
|
| 105 | - $this->filter = $filter; |
|
| 106 | - } else { |
|
| 107 | - $this->filter->addNext($filter); |
|
| 108 | - } |
|
| 109 | - } |
|
| 99 | + /** |
|
| 100 | + * Adds a filter to the end of the filter chain. |
|
| 101 | + * @param LoggerFilter $filter add a new LoggerFilter |
|
| 102 | + */ |
|
| 103 | + public function addFilter($filter) { |
|
| 104 | + if($this->filter === null) { |
|
| 105 | + $this->filter = $filter; |
|
| 106 | + } else { |
|
| 107 | + $this->filter->addNext($filter); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Clears the filter chain by removing all the filters in it. |
|
| 113 | - */ |
|
| 114 | - public function clearFilters() { |
|
| 115 | - $this->filter = null; |
|
| 116 | - } |
|
| 111 | + /** |
|
| 112 | + * Clears the filter chain by removing all the filters in it. |
|
| 113 | + */ |
|
| 114 | + public function clearFilters() { |
|
| 115 | + $this->filter = null; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Returns the first filter in the filter chain. |
|
| 120 | - * The return value may be <i>null</i> if no is filter is set. |
|
| 121 | - * @return LoggerFilter |
|
| 122 | - */ |
|
| 123 | - public function getFilter() { |
|
| 124 | - return $this->filter; |
|
| 125 | - } |
|
| 118 | + /** |
|
| 119 | + * Returns the first filter in the filter chain. |
|
| 120 | + * The return value may be <i>null</i> if no is filter is set. |
|
| 121 | + * @return LoggerFilter |
|
| 122 | + */ |
|
| 123 | + public function getFilter() { |
|
| 124 | + return $this->filter; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Returns the first filter in the filter chain. |
|
| 129 | - * The return value may be <i>null</i> if no is filter is set. |
|
| 130 | - * @return LoggerFilter |
|
| 131 | - */ |
|
| 132 | - public function getFirstFilter() { |
|
| 133 | - return $this->filter; |
|
| 134 | - } |
|
| 127 | + /** |
|
| 128 | + * Returns the first filter in the filter chain. |
|
| 129 | + * The return value may be <i>null</i> if no is filter is set. |
|
| 130 | + * @return LoggerFilter |
|
| 131 | + */ |
|
| 132 | + public function getFirstFilter() { |
|
| 133 | + return $this->filter; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Performs threshold checks and invokes filters before delegating logging |
|
| 138 | - * to the subclass' specific <i>append()</i> method. |
|
| 139 | - * @see Payone_Log4php_LoggerAppender::append() |
|
| 140 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 141 | - */ |
|
| 142 | - public function doAppend(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 143 | - if($this->closed) { |
|
| 144 | - return; |
|
| 145 | - } |
|
| 136 | + /** |
|
| 137 | + * Performs threshold checks and invokes filters before delegating logging |
|
| 138 | + * to the subclass' specific <i>append()</i> method. |
|
| 139 | + * @see Payone_Log4php_LoggerAppender::append() |
|
| 140 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 141 | + */ |
|
| 142 | + public function doAppend(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 143 | + if($this->closed) { |
|
| 144 | + return; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 148 | - return; |
|
| 149 | - } |
|
| 147 | + if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 148 | + return; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - $f = $this->getFirstFilter(); |
|
| 152 | - while($f !== null) { |
|
| 153 | - switch ($f->decide($event)) { |
|
| 154 | - case Payone_Log4php_LoggerFilter::DENY: return; |
|
| 155 | - case Payone_Log4php_LoggerFilter::ACCEPT: return $this->append($event); |
|
| 156 | - case Payone_Log4php_LoggerFilter::NEUTRAL: $f = $f->getNext(); |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - $this->append($event); |
|
| 160 | - } |
|
| 151 | + $f = $this->getFirstFilter(); |
|
| 152 | + while($f !== null) { |
|
| 153 | + switch ($f->decide($event)) { |
|
| 154 | + case Payone_Log4php_LoggerFilter::DENY: return; |
|
| 155 | + case Payone_Log4php_LoggerFilter::ACCEPT: return $this->append($event); |
|
| 156 | + case Payone_Log4php_LoggerFilter::NEUTRAL: $f = $f->getNext(); |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + $this->append($event); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Sets the appender layout. |
|
| 164 | - * @param Payone_Log4php_LoggerLayout $layout |
|
| 165 | - */ |
|
| 166 | - public function setLayout($layout) { |
|
| 167 | - if($this->requiresLayout()) { |
|
| 168 | - $this->layout = $layout; |
|
| 169 | - } |
|
| 170 | - } |
|
| 162 | + /** |
|
| 163 | + * Sets the appender layout. |
|
| 164 | + * @param Payone_Log4php_LoggerLayout $layout |
|
| 165 | + */ |
|
| 166 | + public function setLayout($layout) { |
|
| 167 | + if($this->requiresLayout()) { |
|
| 168 | + $this->layout = $layout; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Returns the appender layout. |
|
| 174 | - * @return Payone_Log4php_LoggerLayout |
|
| 175 | - */ |
|
| 176 | - public function getLayout() { |
|
| 177 | - return $this->layout; |
|
| 178 | - } |
|
| 172 | + /** |
|
| 173 | + * Returns the appender layout. |
|
| 174 | + * @return Payone_Log4php_LoggerLayout |
|
| 175 | + */ |
|
| 176 | + public function getLayout() { |
|
| 177 | + return $this->layout; |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Configurators call this method to determine if the appender |
|
| 182 | - * requires a layout. |
|
| 183 | - * |
|
| 184 | - * <p>If this method returns <i>true</i>, meaning that layout is required, |
|
| 185 | - * then the configurator will configure a layout using the configuration |
|
| 186 | - * information at its disposal. If this method returns <i>false</i>, |
|
| 187 | - * meaning that a layout is not required, then layout configuration will be |
|
| 188 | - * skipped even if there is available layout configuration |
|
| 189 | - * information at the disposal of the configurator.</p> |
|
| 190 | - * |
|
| 191 | - * <p>In the rather exceptional case, where the appender |
|
| 192 | - * implementation admits a layout but can also work without it, then |
|
| 193 | - * the appender should return <i>true</i>.</p> |
|
| 194 | - * |
|
| 195 | - * @return boolean |
|
| 196 | - */ |
|
| 197 | - public function requiresLayout() { |
|
| 198 | - return $this->requiresLayout; |
|
| 199 | - } |
|
| 180 | + /** |
|
| 181 | + * Configurators call this method to determine if the appender |
|
| 182 | + * requires a layout. |
|
| 183 | + * |
|
| 184 | + * <p>If this method returns <i>true</i>, meaning that layout is required, |
|
| 185 | + * then the configurator will configure a layout using the configuration |
|
| 186 | + * information at its disposal. If this method returns <i>false</i>, |
|
| 187 | + * meaning that a layout is not required, then layout configuration will be |
|
| 188 | + * skipped even if there is available layout configuration |
|
| 189 | + * information at the disposal of the configurator.</p> |
|
| 190 | + * |
|
| 191 | + * <p>In the rather exceptional case, where the appender |
|
| 192 | + * implementation admits a layout but can also work without it, then |
|
| 193 | + * the appender should return <i>true</i>.</p> |
|
| 194 | + * |
|
| 195 | + * @return boolean |
|
| 196 | + */ |
|
| 197 | + public function requiresLayout() { |
|
| 198 | + return $this->requiresLayout; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Retruns the appender name. |
|
| 203 | - * @return string |
|
| 204 | - */ |
|
| 205 | - public function getName() { |
|
| 206 | - return $this->name; |
|
| 207 | - } |
|
| 201 | + /** |
|
| 202 | + * Retruns the appender name. |
|
| 203 | + * @return string |
|
| 204 | + */ |
|
| 205 | + public function getName() { |
|
| 206 | + return $this->name; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Sets the appender name. |
|
| 211 | - * @param string $name |
|
| 212 | - */ |
|
| 213 | - public function setName($name) { |
|
| 214 | - $this->name = $name; |
|
| 215 | - } |
|
| 209 | + /** |
|
| 210 | + * Sets the appender name. |
|
| 211 | + * @param string $name |
|
| 212 | + */ |
|
| 213 | + public function setName($name) { |
|
| 214 | + $this->name = $name; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Returns the appender's threshold level. |
|
| 219 | - * @return Payone_Log4php_LoggerLevel |
|
| 220 | - */ |
|
| 221 | - public function getThreshold() { |
|
| 222 | - return $this->threshold; |
|
| 223 | - } |
|
| 217 | + /** |
|
| 218 | + * Returns the appender's threshold level. |
|
| 219 | + * @return Payone_Log4php_LoggerLevel |
|
| 220 | + */ |
|
| 221 | + public function getThreshold() { |
|
| 222 | + return $this->threshold; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - /** |
|
| 226 | - * Sets the appender threshold. |
|
| 227 | - * |
|
| 228 | - * @param Payone_Log4php_LoggerLevel|string $threshold Either a {@link LoggerLevel} |
|
| 229 | - * object or a string equivalent. |
|
| 230 | - * @see LoggerOptionConverter::toLevel() |
|
| 231 | - */ |
|
| 232 | - public function setThreshold($threshold) { |
|
| 233 | - $this->setLevel('threshold', $threshold); |
|
| 234 | - } |
|
| 225 | + /** |
|
| 226 | + * Sets the appender threshold. |
|
| 227 | + * |
|
| 228 | + * @param Payone_Log4php_LoggerLevel|string $threshold Either a {@link LoggerLevel} |
|
| 229 | + * object or a string equivalent. |
|
| 230 | + * @see LoggerOptionConverter::toLevel() |
|
| 231 | + */ |
|
| 232 | + public function setThreshold($threshold) { |
|
| 233 | + $this->setLevel('threshold', $threshold); |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - /** |
|
| 237 | - * Checks whether the message level is below the appender's threshold. |
|
| 238 | - * |
|
| 239 | - * If there is no threshold set, then the return value is always <i>true</i>. |
|
| 240 | - * |
|
| 241 | - * @param Payone_Log4php_LoggerLevel $level |
|
| 242 | - * @return boolean Returns true if level is greater or equal than |
|
| 243 | - * threshold, or if the threshold is not set. Otherwise returns false. |
|
| 244 | - */ |
|
| 245 | - public function isAsSevereAsThreshold($level) { |
|
| 246 | - if($this->threshold === null) { |
|
| 247 | - return true; |
|
| 248 | - } |
|
| 249 | - return $level->isGreaterOrEqual($this->getThreshold()); |
|
| 250 | - } |
|
| 236 | + /** |
|
| 237 | + * Checks whether the message level is below the appender's threshold. |
|
| 238 | + * |
|
| 239 | + * If there is no threshold set, then the return value is always <i>true</i>. |
|
| 240 | + * |
|
| 241 | + * @param Payone_Log4php_LoggerLevel $level |
|
| 242 | + * @return boolean Returns true if level is greater or equal than |
|
| 243 | + * threshold, or if the threshold is not set. Otherwise returns false. |
|
| 244 | + */ |
|
| 245 | + public function isAsSevereAsThreshold($level) { |
|
| 246 | + if($this->threshold === null) { |
|
| 247 | + return true; |
|
| 248 | + } |
|
| 249 | + return $level->isGreaterOrEqual($this->getThreshold()); |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Prepares the appender for logging. |
|
| 254 | - * |
|
| 255 | - * Derived appenders should override this method if option structure |
|
| 256 | - * requires it. |
|
| 257 | - */ |
|
| 258 | - public function activateOptions() { |
|
| 259 | - $this->closed = false; |
|
| 260 | - } |
|
| 252 | + /** |
|
| 253 | + * Prepares the appender for logging. |
|
| 254 | + * |
|
| 255 | + * Derived appenders should override this method if option structure |
|
| 256 | + * requires it. |
|
| 257 | + */ |
|
| 258 | + public function activateOptions() { |
|
| 259 | + $this->closed = false; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Forwards the logging event to the destination. |
|
| 264 | - * |
|
| 265 | - * Derived appenders should implement this method to perform actual logging. |
|
| 266 | - * |
|
| 267 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 268 | - */ |
|
| 269 | - abstract protected function append(Payone_Log4php_LoggerLoggingEvent $event); |
|
| 262 | + /** |
|
| 263 | + * Forwards the logging event to the destination. |
|
| 264 | + * |
|
| 265 | + * Derived appenders should implement this method to perform actual logging. |
|
| 266 | + * |
|
| 267 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 268 | + */ |
|
| 269 | + abstract protected function append(Payone_Log4php_LoggerLoggingEvent $event); |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Releases any resources allocated by the appender. |
|
| 273 | - * |
|
| 274 | - * Derived appenders should override this method to perform proper closing |
|
| 275 | - * procedures. |
|
| 276 | - */ |
|
| 277 | - public function close() { |
|
| 278 | - $this->closed = true; |
|
| 279 | - } |
|
| 271 | + /** |
|
| 272 | + * Releases any resources allocated by the appender. |
|
| 273 | + * |
|
| 274 | + * Derived appenders should override this method to perform proper closing |
|
| 275 | + * procedures. |
|
| 276 | + */ |
|
| 277 | + public function close() { |
|
| 278 | + $this->closed = true; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** Triggers a warning for this logger with the given message. */ |
|
| 282 | - protected function warn($message) { |
|
| 283 | - $id = get_class($this) . (empty($this->name) ? '' : ":{$this->name}"); |
|
| 284 | - trigger_error("log4php: [$id]: $message", E_USER_WARNING); |
|
| 285 | - } |
|
| 281 | + /** Triggers a warning for this logger with the given message. */ |
|
| 282 | + protected function warn($message) { |
|
| 283 | + $id = get_class($this) . (empty($this->name) ? '' : ":{$this->name}"); |
|
| 284 | + trigger_error("log4php: [$id]: $message", E_USER_WARNING); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param LoggerFilter $filter add a new LoggerFilter |
| 102 | 102 | */ |
| 103 | 103 | public function addFilter($filter) { |
| 104 | - if($this->filter === null) { |
|
| 104 | + if ($this->filter === null) { |
|
| 105 | 105 | $this->filter = $filter; |
| 106 | 106 | } else { |
| 107 | 107 | $this->filter->addNext($filter); |
@@ -140,16 +140,16 @@ discard block |
||
| 140 | 140 | * @param Payone_Log4php_LoggerLoggingEvent $event |
| 141 | 141 | */ |
| 142 | 142 | public function doAppend(Payone_Log4php_LoggerLoggingEvent $event) { |
| 143 | - if($this->closed) { |
|
| 143 | + if ($this->closed) { |
|
| 144 | 144 | return; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - if(!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 147 | + if (!$this->isAsSevereAsThreshold($event->getLevel())) { |
|
| 148 | 148 | return; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | $f = $this->getFirstFilter(); |
| 152 | - while($f !== null) { |
|
| 152 | + while ($f !== null) { |
|
| 153 | 153 | switch ($f->decide($event)) { |
| 154 | 154 | case Payone_Log4php_LoggerFilter::DENY: return; |
| 155 | 155 | case Payone_Log4php_LoggerFilter::ACCEPT: return $this->append($event); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | * @param Payone_Log4php_LoggerLayout $layout |
| 165 | 165 | */ |
| 166 | 166 | public function setLayout($layout) { |
| 167 | - if($this->requiresLayout()) { |
|
| 167 | + if ($this->requiresLayout()) { |
|
| 168 | 168 | $this->layout = $layout; |
| 169 | 169 | } |
| 170 | 170 | } |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | * threshold, or if the threshold is not set. Otherwise returns false. |
| 244 | 244 | */ |
| 245 | 245 | public function isAsSevereAsThreshold($level) { |
| 246 | - if($this->threshold === null) { |
|
| 246 | + if ($this->threshold === null) { |
|
| 247 | 247 | return true; |
| 248 | 248 | } |
| 249 | 249 | return $level->isGreaterOrEqual($this->getThreshold()); |
@@ -42,121 +42,121 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class Payone_Log4php_LoggerAppenderFile extends Payone_Log4php_LoggerAppender { |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var boolean if {@link $file} exists, appends events. |
|
| 47 | - */ |
|
| 48 | - protected $append = true; |
|
| 45 | + /** |
|
| 46 | + * @var boolean if {@link $file} exists, appends events. |
|
| 47 | + */ |
|
| 48 | + protected $append = true; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var string the file name used to append events |
|
| 52 | - */ |
|
| 53 | - protected $file; |
|
| 50 | + /** |
|
| 51 | + * @var string the file name used to append events |
|
| 52 | + */ |
|
| 53 | + protected $file; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var mixed file resource |
|
| 57 | - */ |
|
| 58 | - protected $fp = false; |
|
| 55 | + /** |
|
| 56 | + * @var mixed file resource |
|
| 57 | + */ |
|
| 58 | + protected $fp = false; |
|
| 59 | 59 | |
| 60 | - public function activateOptions() { |
|
| 61 | - $fileName = $this->getFile(); |
|
| 60 | + public function activateOptions() { |
|
| 61 | + $fileName = $this->getFile(); |
|
| 62 | 62 | |
| 63 | - if (empty($fileName)) { |
|
| 64 | - $this->warn("Required parameter 'fileName' not set. Closing appender."); |
|
| 65 | - $this->closed = true; |
|
| 66 | - return; |
|
| 67 | - } |
|
| 63 | + if (empty($fileName)) { |
|
| 64 | + $this->warn("Required parameter 'fileName' not set. Closing appender."); |
|
| 65 | + $this->closed = true; |
|
| 66 | + return; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - if(!is_file($fileName)) { |
|
| 70 | - $dir = dirname($fileName); |
|
| 71 | - if(!is_dir($dir)) { |
|
| 72 | - mkdir($dir, 0777, true); |
|
| 73 | - } |
|
| 74 | - } |
|
| 69 | + if(!is_file($fileName)) { |
|
| 70 | + $dir = dirname($fileName); |
|
| 71 | + if(!is_dir($dir)) { |
|
| 72 | + mkdir($dir, 0777, true); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
| 77 | - if($this->fp) { |
|
| 78 | - if(flock($this->fp, LOCK_EX)) { |
|
| 79 | - if($this->getAppend()) { |
|
| 80 | - fseek($this->fp, 0, SEEK_END); |
|
| 81 | - } |
|
| 82 | - fwrite($this->fp, $this->layout->getHeader()); |
|
| 83 | - flock($this->fp, LOCK_UN); |
|
| 84 | - $this->closed = false; |
|
| 85 | - } else { |
|
| 86 | - // TODO: should we take some action in this case? |
|
| 87 | - $this->closed = true; |
|
| 88 | - } |
|
| 89 | - } else { |
|
| 90 | - $this->closed = true; |
|
| 91 | - } |
|
| 92 | - } |
|
| 76 | + $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
| 77 | + if($this->fp) { |
|
| 78 | + if(flock($this->fp, LOCK_EX)) { |
|
| 79 | + if($this->getAppend()) { |
|
| 80 | + fseek($this->fp, 0, SEEK_END); |
|
| 81 | + } |
|
| 82 | + fwrite($this->fp, $this->layout->getHeader()); |
|
| 83 | + flock($this->fp, LOCK_UN); |
|
| 84 | + $this->closed = false; |
|
| 85 | + } else { |
|
| 86 | + // TODO: should we take some action in this case? |
|
| 87 | + $this->closed = true; |
|
| 88 | + } |
|
| 89 | + } else { |
|
| 90 | + $this->closed = true; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - public function close() { |
|
| 95 | - if($this->closed != true) { |
|
| 96 | - if($this->fp and $this->layout !== null) { |
|
| 97 | - if(flock($this->fp, LOCK_EX)) { |
|
| 98 | - fwrite($this->fp, $this->layout->getFooter()); |
|
| 99 | - flock($this->fp, LOCK_UN); |
|
| 100 | - } |
|
| 101 | - fclose($this->fp); |
|
| 102 | - } |
|
| 103 | - $this->closed = true; |
|
| 104 | - } |
|
| 105 | - } |
|
| 94 | + public function close() { |
|
| 95 | + if($this->closed != true) { |
|
| 96 | + if($this->fp and $this->layout !== null) { |
|
| 97 | + if(flock($this->fp, LOCK_EX)) { |
|
| 98 | + fwrite($this->fp, $this->layout->getFooter()); |
|
| 99 | + flock($this->fp, LOCK_UN); |
|
| 100 | + } |
|
| 101 | + fclose($this->fp); |
|
| 102 | + } |
|
| 103 | + $this->closed = true; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 108 | - if($this->fp and $this->layout !== null) { |
|
| 109 | - if(flock($this->fp, LOCK_EX)) { |
|
| 110 | - fwrite($this->fp, $this->layout->format($event)); |
|
| 111 | - flock($this->fp, LOCK_UN); |
|
| 112 | - } else { |
|
| 113 | - $this->closed = true; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - } |
|
| 107 | + public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 108 | + if($this->fp and $this->layout !== null) { |
|
| 109 | + if(flock($this->fp, LOCK_EX)) { |
|
| 110 | + fwrite($this->fp, $this->layout->format($event)); |
|
| 111 | + flock($this->fp, LOCK_UN); |
|
| 112 | + } else { |
|
| 113 | + $this->closed = true; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Sets the file where the log output will go. |
|
| 120 | - * @param string $file |
|
| 121 | - */ |
|
| 122 | - public function setFile($file) { |
|
| 123 | - $this->setString('file', $file); |
|
| 124 | - } |
|
| 118 | + /** |
|
| 119 | + * Sets the file where the log output will go. |
|
| 120 | + * @param string $file |
|
| 121 | + */ |
|
| 122 | + public function setFile($file) { |
|
| 123 | + $this->setString('file', $file); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getFile() { |
|
| 130 | - return $this->file; |
|
| 131 | - } |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getFile() { |
|
| 130 | + return $this->file; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * @return boolean |
|
| 135 | - */ |
|
| 136 | - public function getAppend() { |
|
| 137 | - return $this->append; |
|
| 138 | - } |
|
| 133 | + /** |
|
| 134 | + * @return boolean |
|
| 135 | + */ |
|
| 136 | + public function getAppend() { |
|
| 137 | + return $this->append; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - public function setAppend($append) { |
|
| 141 | - $this->setBoolean('append', $append); |
|
| 142 | - } |
|
| 140 | + public function setAppend($append) { |
|
| 141 | + $this->setBoolean('append', $append); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Sets the file where the log output will go. |
|
| 146 | - * @param string $fileName |
|
| 147 | - * @deprecated Use setFile() instead. |
|
| 148 | - */ |
|
| 149 | - public function setFileName($fileName) { |
|
| 150 | - $this->setFile($fileName); |
|
| 151 | - } |
|
| 144 | + /** |
|
| 145 | + * Sets the file where the log output will go. |
|
| 146 | + * @param string $fileName |
|
| 147 | + * @deprecated Use setFile() instead. |
|
| 148 | + */ |
|
| 149 | + public function setFileName($fileName) { |
|
| 150 | + $this->setFile($fileName); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * @return string |
|
| 155 | - * @deprecated Use getFile() instead. |
|
| 156 | - */ |
|
| 157 | - public function getFileName() { |
|
| 158 | - return $this->getFile(); |
|
| 159 | - } |
|
| 153 | + /** |
|
| 154 | + * @return string |
|
| 155 | + * @deprecated Use getFile() instead. |
|
| 156 | + */ |
|
| 157 | + public function getFileName() { |
|
| 158 | + return $this->getFile(); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | 161 | |
| 162 | 162 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | return; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if(!is_file($fileName)) { |
|
| 69 | + if (!is_file($fileName)) { |
|
| 70 | 70 | $dir = dirname($fileName); |
| 71 | - if(!is_dir($dir)) { |
|
| 71 | + if (!is_dir($dir)) { |
|
| 72 | 72 | mkdir($dir, 0777, true); |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); |
|
| 77 | - if($this->fp) { |
|
| 78 | - if(flock($this->fp, LOCK_EX)) { |
|
| 79 | - if($this->getAppend()) { |
|
| 76 | + $this->fp = fopen($fileName, ($this->getAppend() ? 'a' : 'w')); |
|
| 77 | + if ($this->fp) { |
|
| 78 | + if (flock($this->fp, LOCK_EX)) { |
|
| 79 | + if ($this->getAppend()) { |
|
| 80 | 80 | fseek($this->fp, 0, SEEK_END); |
| 81 | 81 | } |
| 82 | 82 | fwrite($this->fp, $this->layout->getHeader()); |
@@ -92,9 +92,9 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | public function close() { |
| 95 | - if($this->closed != true) { |
|
| 96 | - if($this->fp and $this->layout !== null) { |
|
| 97 | - if(flock($this->fp, LOCK_EX)) { |
|
| 95 | + if ($this->closed != true) { |
|
| 96 | + if ($this->fp and $this->layout !== null) { |
|
| 97 | + if (flock($this->fp, LOCK_EX)) { |
|
| 98 | 98 | fwrite($this->fp, $this->layout->getFooter()); |
| 99 | 99 | flock($this->fp, LOCK_UN); |
| 100 | 100 | } |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
| 108 | - if($this->fp and $this->layout !== null) { |
|
| 109 | - if(flock($this->fp, LOCK_EX)) { |
|
| 108 | + if ($this->fp and $this->layout !== null) { |
|
| 109 | + if (flock($this->fp, LOCK_EX)) { |
|
| 110 | 110 | fwrite($this->fp, $this->layout->format($event)); |
| 111 | 111 | flock($this->fp, LOCK_UN); |
| 112 | 112 | } else { |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Payone_Log4php_LoggerPatternConverterFile extends Payone_Log4php_LoggerPatternConverter { |
| 28 | 28 | |
| 29 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | - return $event->getLocationInformation()->getFileName(); |
|
| 31 | - } |
|
| 29 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | + return $event->getLocationInformation()->getFileName(); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -41,531 +41,531 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Payone_Log4php_Logger { |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Logger additivity. If set to true then child loggers will inherit |
|
| 46 | - * the appenders of their ancestors by default. |
|
| 47 | - * @var boolean |
|
| 48 | - */ |
|
| 49 | - private $additive = true; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The Logger's fully qualified class name. |
|
| 53 | - * TODO: Determine if this is useful. |
|
| 54 | - */ |
|
| 55 | - private $fqcn = 'Logger'; |
|
| 44 | + /** |
|
| 45 | + * Logger additivity. If set to true then child loggers will inherit |
|
| 46 | + * the appenders of their ancestors by default. |
|
| 47 | + * @var boolean |
|
| 48 | + */ |
|
| 49 | + private $additive = true; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The Logger's fully qualified class name. |
|
| 53 | + * TODO: Determine if this is useful. |
|
| 54 | + */ |
|
| 55 | + private $fqcn = 'Logger'; |
|
| 56 | 56 | |
| 57 | - /** The assigned Logger level. */ |
|
| 58 | - private $level; |
|
| 57 | + /** The assigned Logger level. */ |
|
| 58 | + private $level; |
|
| 59 | 59 | |
| 60 | - /** The name of this Logger instance. */ |
|
| 61 | - private $name; |
|
| 60 | + /** The name of this Logger instance. */ |
|
| 61 | + private $name; |
|
| 62 | 62 | |
| 63 | - /** The parent logger. Set to null if this is the root logger. */ |
|
| 64 | - private $parent; |
|
| 63 | + /** The parent logger. Set to null if this is the root logger. */ |
|
| 64 | + private $parent; |
|
| 65 | 65 | |
| 66 | - /** A collection of appenders linked to this logger. */ |
|
| 67 | - private $appenders = array(); |
|
| 66 | + /** A collection of appenders linked to this logger. */ |
|
| 67 | + private $appenders = array(); |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Constructor. |
|
| 71 | - * @param string $name Name of the logger. |
|
| 72 | - */ |
|
| 73 | - public function __construct($name) { |
|
| 74 | - $this->name = $name; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Returns the logger name. |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function getName() { |
|
| 82 | - return $this->name; |
|
| 83 | - } |
|
| 69 | + /** |
|
| 70 | + * Constructor. |
|
| 71 | + * @param string $name Name of the logger. |
|
| 72 | + */ |
|
| 73 | + public function __construct($name) { |
|
| 74 | + $this->name = $name; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Returns the logger name. |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function getName() { |
|
| 82 | + return $this->name; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Returns the parent Logger. Can be null if this is the root logger. |
|
| 87 | - * @return Logger |
|
| 88 | - */ |
|
| 89 | - public function getParent() { |
|
| 90 | - return $this->parent; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // ****************************************** |
|
| 94 | - // *** Logging methods *** |
|
| 95 | - // ****************************************** |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Log a message object with the TRACE level. |
|
| 99 | - * |
|
| 100 | - * @param mixed $message message |
|
| 101 | - * @param Exception $throwable Optional throwable information to include |
|
| 102 | - * in the logging event. |
|
| 103 | - */ |
|
| 104 | - public function trace($message, $throwable = null) { |
|
| 105 | - $this->log(Payone_Log4php_LoggerLevel::getLevelTrace(), $message, $throwable); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Log a message object with the DEBUG level. |
|
| 110 | - * |
|
| 111 | - * @param mixed $message message |
|
| 112 | - * @param Exception $throwable Optional throwable information to include |
|
| 113 | - * in the logging event. |
|
| 114 | - */ |
|
| 115 | - public function debug($message, $throwable = null) { |
|
| 116 | - $this->log(Payone_Log4php_LoggerLevel::getLevelDebug(), $message, $throwable); |
|
| 117 | - } |
|
| 85 | + /** |
|
| 86 | + * Returns the parent Logger. Can be null if this is the root logger. |
|
| 87 | + * @return Logger |
|
| 88 | + */ |
|
| 89 | + public function getParent() { |
|
| 90 | + return $this->parent; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // ****************************************** |
|
| 94 | + // *** Logging methods *** |
|
| 95 | + // ****************************************** |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Log a message object with the TRACE level. |
|
| 99 | + * |
|
| 100 | + * @param mixed $message message |
|
| 101 | + * @param Exception $throwable Optional throwable information to include |
|
| 102 | + * in the logging event. |
|
| 103 | + */ |
|
| 104 | + public function trace($message, $throwable = null) { |
|
| 105 | + $this->log(Payone_Log4php_LoggerLevel::getLevelTrace(), $message, $throwable); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Log a message object with the DEBUG level. |
|
| 110 | + * |
|
| 111 | + * @param mixed $message message |
|
| 112 | + * @param Exception $throwable Optional throwable information to include |
|
| 113 | + * in the logging event. |
|
| 114 | + */ |
|
| 115 | + public function debug($message, $throwable = null) { |
|
| 116 | + $this->log(Payone_Log4php_LoggerLevel::getLevelDebug(), $message, $throwable); |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - /** |
|
| 120 | - * Log a message object with the INFO Level. |
|
| 121 | - * |
|
| 122 | - * @param mixed $message message |
|
| 123 | - * @param Exception $throwable Optional throwable information to include |
|
| 124 | - * in the logging event. |
|
| 125 | - */ |
|
| 126 | - public function info($message, $throwable = null) { |
|
| 127 | - $this->log(Payone_Log4php_LoggerLevel::getLevelInfo(), $message, $throwable); |
|
| 128 | - } |
|
| 119 | + /** |
|
| 120 | + * Log a message object with the INFO Level. |
|
| 121 | + * |
|
| 122 | + * @param mixed $message message |
|
| 123 | + * @param Exception $throwable Optional throwable information to include |
|
| 124 | + * in the logging event. |
|
| 125 | + */ |
|
| 126 | + public function info($message, $throwable = null) { |
|
| 127 | + $this->log(Payone_Log4php_LoggerLevel::getLevelInfo(), $message, $throwable); |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Log a message with the WARN level. |
|
| 132 | - * |
|
| 133 | - * @param mixed $message message |
|
| 134 | - * @param Exception $throwable Optional throwable information to include |
|
| 135 | - * in the logging event. |
|
| 136 | - */ |
|
| 137 | - public function warn($message, $throwable = null) { |
|
| 138 | - $this->log(Payone_Log4php_LoggerLevel::getLevelWarn(), $message, $throwable); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Log a message object with the ERROR level. |
|
| 143 | - * |
|
| 144 | - * @param mixed $message message |
|
| 145 | - * @param Exception $throwable Optional throwable information to include |
|
| 146 | - * in the logging event. |
|
| 147 | - */ |
|
| 148 | - public function error($message, $throwable = null) { |
|
| 149 | - $this->log(Payone_Log4php_LoggerLevel::getLevelError(), $message, $throwable); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Log a message object with the FATAL level. |
|
| 154 | - * |
|
| 155 | - * @param mixed $message message |
|
| 156 | - * @param Exception $throwable Optional throwable information to include |
|
| 157 | - * in the logging event. |
|
| 158 | - */ |
|
| 159 | - public function fatal($message, $throwable = null) { |
|
| 160 | - $this->log(Payone_Log4php_LoggerLevel::getLevelFatal(), $message, $throwable); |
|
| 161 | - } |
|
| 130 | + /** |
|
| 131 | + * Log a message with the WARN level. |
|
| 132 | + * |
|
| 133 | + * @param mixed $message message |
|
| 134 | + * @param Exception $throwable Optional throwable information to include |
|
| 135 | + * in the logging event. |
|
| 136 | + */ |
|
| 137 | + public function warn($message, $throwable = null) { |
|
| 138 | + $this->log(Payone_Log4php_LoggerLevel::getLevelWarn(), $message, $throwable); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Log a message object with the ERROR level. |
|
| 143 | + * |
|
| 144 | + * @param mixed $message message |
|
| 145 | + * @param Exception $throwable Optional throwable information to include |
|
| 146 | + * in the logging event. |
|
| 147 | + */ |
|
| 148 | + public function error($message, $throwable = null) { |
|
| 149 | + $this->log(Payone_Log4php_LoggerLevel::getLevelError(), $message, $throwable); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Log a message object with the FATAL level. |
|
| 154 | + * |
|
| 155 | + * @param mixed $message message |
|
| 156 | + * @param Exception $throwable Optional throwable information to include |
|
| 157 | + * in the logging event. |
|
| 158 | + */ |
|
| 159 | + public function fatal($message, $throwable = null) { |
|
| 160 | + $this->log(Payone_Log4php_LoggerLevel::getLevelFatal(), $message, $throwable); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Log a message using the provided logging level. |
|
| 165 | - * |
|
| 166 | - * @param Payone_Log4php_LoggerLevel $level The logging level. |
|
| 167 | - * @param mixed $message Message to log. |
|
| 168 | - * @param Exception $throwable Optional throwable information to include |
|
| 169 | - * in the logging event. |
|
| 170 | - */ |
|
| 171 | - public function log(Payone_Log4php_LoggerLevel $level, $message, $throwable = null) { |
|
| 172 | - if($this->isEnabledFor($level)) { |
|
| 173 | - $this->forcedLog($this->fqcn, $throwable, $level, $message); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * If assertion parameter evaluates as false, then logs the message |
|
| 179 | - * using the ERROR level. |
|
| 180 | - * |
|
| 181 | - * @param bool $assertion |
|
| 182 | - * @param string $msg message to log |
|
| 183 | - */ |
|
| 184 | - public function assertLog($assertion = true, $msg = '') { |
|
| 185 | - if($assertion == false) { |
|
| 186 | - $this->error($msg); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * This method creates a new logging event and logs the event without |
|
| 192 | - * further checks. |
|
| 193 | - * |
|
| 194 | - * It should not be called directly. Use {@link trace()}, {@link debug()}, |
|
| 195 | - * {@link info()}, {@link warn()}, {@link error()} and {@link fatal()} |
|
| 196 | - * wrappers. |
|
| 197 | - * |
|
| 198 | - * @param string $fqcn Fully qualified class name of the Logger |
|
| 199 | - * @param Exception $throwable Optional throwable information to include |
|
| 200 | - * in the logging event. |
|
| 201 | - * @param Payone_Log4php_LoggerLevel $level log level |
|
| 202 | - * @param mixed $message message to log |
|
| 203 | - */ |
|
| 204 | - public function forcedLog($fqcn, $throwable, Payone_Log4php_LoggerLevel $level, $message) { |
|
| 205 | - if (!($throwable instanceof Exception)) { |
|
| 206 | - $throwable = null; |
|
| 207 | - } |
|
| 208 | - $this->callAppenders(new Payone_Log4php_LoggerLoggingEvent($fqcn, $this, $level, $message, null, $throwable)); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // ****************************************** |
|
| 212 | - // *** Checker methods *** |
|
| 213 | - // ****************************************** |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Check whether this Logger is enabled for a given Level passed as parameter. |
|
| 217 | - * |
|
| 218 | - * @param LoggerLevel level |
|
| 219 | - * @return boolean |
|
| 220 | - */ |
|
| 221 | - public function isEnabledFor(Payone_Log4php_LoggerLevel $level) { |
|
| 222 | - return $level->isGreaterOrEqual($this->getEffectiveLevel()); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * Check whether this Logger is enabled for the TRACE Level. |
|
| 227 | - * @return boolean |
|
| 228 | - */ |
|
| 229 | - public function isTraceEnabled() { |
|
| 230 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelTrace()); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Check whether this Logger is enabled for the DEBUG Level. |
|
| 235 | - * @return boolean |
|
| 236 | - */ |
|
| 237 | - public function isDebugEnabled() { |
|
| 238 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelDebug()); |
|
| 239 | - } |
|
| 163 | + /** |
|
| 164 | + * Log a message using the provided logging level. |
|
| 165 | + * |
|
| 166 | + * @param Payone_Log4php_LoggerLevel $level The logging level. |
|
| 167 | + * @param mixed $message Message to log. |
|
| 168 | + * @param Exception $throwable Optional throwable information to include |
|
| 169 | + * in the logging event. |
|
| 170 | + */ |
|
| 171 | + public function log(Payone_Log4php_LoggerLevel $level, $message, $throwable = null) { |
|
| 172 | + if($this->isEnabledFor($level)) { |
|
| 173 | + $this->forcedLog($this->fqcn, $throwable, $level, $message); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * If assertion parameter evaluates as false, then logs the message |
|
| 179 | + * using the ERROR level. |
|
| 180 | + * |
|
| 181 | + * @param bool $assertion |
|
| 182 | + * @param string $msg message to log |
|
| 183 | + */ |
|
| 184 | + public function assertLog($assertion = true, $msg = '') { |
|
| 185 | + if($assertion == false) { |
|
| 186 | + $this->error($msg); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * This method creates a new logging event and logs the event without |
|
| 192 | + * further checks. |
|
| 193 | + * |
|
| 194 | + * It should not be called directly. Use {@link trace()}, {@link debug()}, |
|
| 195 | + * {@link info()}, {@link warn()}, {@link error()} and {@link fatal()} |
|
| 196 | + * wrappers. |
|
| 197 | + * |
|
| 198 | + * @param string $fqcn Fully qualified class name of the Logger |
|
| 199 | + * @param Exception $throwable Optional throwable information to include |
|
| 200 | + * in the logging event. |
|
| 201 | + * @param Payone_Log4php_LoggerLevel $level log level |
|
| 202 | + * @param mixed $message message to log |
|
| 203 | + */ |
|
| 204 | + public function forcedLog($fqcn, $throwable, Payone_Log4php_LoggerLevel $level, $message) { |
|
| 205 | + if (!($throwable instanceof Exception)) { |
|
| 206 | + $throwable = null; |
|
| 207 | + } |
|
| 208 | + $this->callAppenders(new Payone_Log4php_LoggerLoggingEvent($fqcn, $this, $level, $message, null, $throwable)); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // ****************************************** |
|
| 212 | + // *** Checker methods *** |
|
| 213 | + // ****************************************** |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Check whether this Logger is enabled for a given Level passed as parameter. |
|
| 217 | + * |
|
| 218 | + * @param LoggerLevel level |
|
| 219 | + * @return boolean |
|
| 220 | + */ |
|
| 221 | + public function isEnabledFor(Payone_Log4php_LoggerLevel $level) { |
|
| 222 | + return $level->isGreaterOrEqual($this->getEffectiveLevel()); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * Check whether this Logger is enabled for the TRACE Level. |
|
| 227 | + * @return boolean |
|
| 228 | + */ |
|
| 229 | + public function isTraceEnabled() { |
|
| 230 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelTrace()); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Check whether this Logger is enabled for the DEBUG Level. |
|
| 235 | + * @return boolean |
|
| 236 | + */ |
|
| 237 | + public function isDebugEnabled() { |
|
| 238 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelDebug()); |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Check whether this Logger is enabled for the INFO Level. |
|
| 243 | - * @return boolean |
|
| 244 | - */ |
|
| 245 | - public function isInfoEnabled() { |
|
| 246 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelInfo()); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Check whether this Logger is enabled for the WARN Level. |
|
| 251 | - * @return boolean |
|
| 252 | - */ |
|
| 253 | - public function isWarnEnabled() { |
|
| 254 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelWarn()); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Check whether this Logger is enabled for the ERROR Level. |
|
| 259 | - * @return boolean |
|
| 260 | - */ |
|
| 261 | - public function isErrorEnabled() { |
|
| 262 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelError()); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Check whether this Logger is enabled for the FATAL Level. |
|
| 267 | - * @return boolean |
|
| 268 | - */ |
|
| 269 | - public function isFatalEnabled() { |
|
| 270 | - return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelFatal()); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // ****************************************** |
|
| 274 | - // *** Configuration methods *** |
|
| 275 | - // ****************************************** |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Adds a new appender to the Logger. |
|
| 279 | - * @param Payone_Log4php_LoggerAppender $appender The appender to add. |
|
| 280 | - */ |
|
| 281 | - public function addAppender($appender) { |
|
| 282 | - $appenderName = $appender->getName(); |
|
| 283 | - $this->appenders[$appenderName] = $appender; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** Removes all appenders from the Logger. */ |
|
| 287 | - public function removeAllAppenders() { |
|
| 288 | - foreach($this->appenders as $name => $appender) { |
|
| 289 | - $this->removeAppender($name); |
|
| 290 | - } |
|
| 291 | - } |
|
| 241 | + /** |
|
| 242 | + * Check whether this Logger is enabled for the INFO Level. |
|
| 243 | + * @return boolean |
|
| 244 | + */ |
|
| 245 | + public function isInfoEnabled() { |
|
| 246 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelInfo()); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Check whether this Logger is enabled for the WARN Level. |
|
| 251 | + * @return boolean |
|
| 252 | + */ |
|
| 253 | + public function isWarnEnabled() { |
|
| 254 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelWarn()); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Check whether this Logger is enabled for the ERROR Level. |
|
| 259 | + * @return boolean |
|
| 260 | + */ |
|
| 261 | + public function isErrorEnabled() { |
|
| 262 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelError()); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Check whether this Logger is enabled for the FATAL Level. |
|
| 267 | + * @return boolean |
|
| 268 | + */ |
|
| 269 | + public function isFatalEnabled() { |
|
| 270 | + return $this->isEnabledFor(Payone_Log4php_LoggerLevel::getLevelFatal()); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // ****************************************** |
|
| 274 | + // *** Configuration methods *** |
|
| 275 | + // ****************************************** |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Adds a new appender to the Logger. |
|
| 279 | + * @param Payone_Log4php_LoggerAppender $appender The appender to add. |
|
| 280 | + */ |
|
| 281 | + public function addAppender($appender) { |
|
| 282 | + $appenderName = $appender->getName(); |
|
| 283 | + $this->appenders[$appenderName] = $appender; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** Removes all appenders from the Logger. */ |
|
| 287 | + public function removeAllAppenders() { |
|
| 288 | + foreach($this->appenders as $name => $appender) { |
|
| 289 | + $this->removeAppender($name); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Remove the appender passed as parameter form the Logger. |
|
| 295 | - * @param mixed $appender an appender name or a {@link Payone_Log4php_LoggerAppender} instance. |
|
| 296 | - */ |
|
| 297 | - public function removeAppender($appender) { |
|
| 298 | - if($appender instanceof Payone_Log4php_LoggerAppender) { |
|
| 299 | - $appender->close(); |
|
| 300 | - unset($this->appenders[$appender->getName()]); |
|
| 301 | - } else if (is_string($appender) and isset($this->appenders[$appender])) { |
|
| 302 | - $this->appenders[$appender]->close(); |
|
| 303 | - unset($this->appenders[$appender]); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Forwards the given logging event to all linked appenders. |
|
| 309 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 310 | - */ |
|
| 311 | - public function callAppenders($event) { |
|
| 312 | - // Forward the event to each linked appender |
|
| 313 | - foreach($this->appenders as $appender) { |
|
| 314 | - $appender->doAppend($event); |
|
| 315 | - } |
|
| 293 | + /** |
|
| 294 | + * Remove the appender passed as parameter form the Logger. |
|
| 295 | + * @param mixed $appender an appender name or a {@link Payone_Log4php_LoggerAppender} instance. |
|
| 296 | + */ |
|
| 297 | + public function removeAppender($appender) { |
|
| 298 | + if($appender instanceof Payone_Log4php_LoggerAppender) { |
|
| 299 | + $appender->close(); |
|
| 300 | + unset($this->appenders[$appender->getName()]); |
|
| 301 | + } else if (is_string($appender) and isset($this->appenders[$appender])) { |
|
| 302 | + $this->appenders[$appender]->close(); |
|
| 303 | + unset($this->appenders[$appender]); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Forwards the given logging event to all linked appenders. |
|
| 309 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 310 | + */ |
|
| 311 | + public function callAppenders($event) { |
|
| 312 | + // Forward the event to each linked appender |
|
| 313 | + foreach($this->appenders as $appender) { |
|
| 314 | + $appender->doAppend($event); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - // Forward the event upstream if additivity is turned on |
|
| 318 | - if(isset($this->parent) && $this->getAdditivity()) { |
|
| 319 | - $this->parent->callAppenders($event); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Returns the appenders linked to this logger as an array. |
|
| 325 | - * @return array collection of appender names |
|
| 326 | - */ |
|
| 327 | - public function getAllAppenders() { |
|
| 328 | - return $this->appenders; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Returns a linked appender by name. |
|
| 333 | - * @return Payone_Log4php_LoggerAppender |
|
| 334 | - */ |
|
| 335 | - public function getAppender($name) { |
|
| 336 | - return $this->appenders[$name]; |
|
| 337 | - } |
|
| 317 | + // Forward the event upstream if additivity is turned on |
|
| 318 | + if(isset($this->parent) && $this->getAdditivity()) { |
|
| 319 | + $this->parent->callAppenders($event); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Returns the appenders linked to this logger as an array. |
|
| 325 | + * @return array collection of appender names |
|
| 326 | + */ |
|
| 327 | + public function getAllAppenders() { |
|
| 328 | + return $this->appenders; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Returns a linked appender by name. |
|
| 333 | + * @return Payone_Log4php_LoggerAppender |
|
| 334 | + */ |
|
| 335 | + public function getAppender($name) { |
|
| 336 | + return $this->appenders[$name]; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - /** |
|
| 340 | - * Sets the additivity flag. |
|
| 341 | - * @param boolean $additive |
|
| 342 | - */ |
|
| 343 | - public function setAdditivity($additive) { |
|
| 344 | - $this->additive = (bool)$additive; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Returns the additivity flag. |
|
| 349 | - * @return boolean |
|
| 350 | - */ |
|
| 351 | - public function getAdditivity() { |
|
| 352 | - return $this->additive; |
|
| 353 | - } |
|
| 339 | + /** |
|
| 340 | + * Sets the additivity flag. |
|
| 341 | + * @param boolean $additive |
|
| 342 | + */ |
|
| 343 | + public function setAdditivity($additive) { |
|
| 344 | + $this->additive = (bool)$additive; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Returns the additivity flag. |
|
| 349 | + * @return boolean |
|
| 350 | + */ |
|
| 351 | + public function getAdditivity() { |
|
| 352 | + return $this->additive; |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Starting from this Logger, search the Logger hierarchy for a non-null level and return it. |
|
| 357 | - * @see LoggerLevel |
|
| 358 | - * @return Payone_Log4php_LoggerLevel or null |
|
| 359 | - */ |
|
| 360 | - public function getEffectiveLevel() { |
|
| 361 | - for($logger = $this; $logger !== null; $logger = $logger->getParent()) { |
|
| 362 | - if($logger->getLevel() !== null) { |
|
| 363 | - return $logger->getLevel(); |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - } |
|
| 355 | + /** |
|
| 356 | + * Starting from this Logger, search the Logger hierarchy for a non-null level and return it. |
|
| 357 | + * @see LoggerLevel |
|
| 358 | + * @return Payone_Log4php_LoggerLevel or null |
|
| 359 | + */ |
|
| 360 | + public function getEffectiveLevel() { |
|
| 361 | + for($logger = $this; $logger !== null; $logger = $logger->getParent()) { |
|
| 362 | + if($logger->getLevel() !== null) { |
|
| 363 | + return $logger->getLevel(); |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - /** |
|
| 369 | - * Get the assigned Logger level. |
|
| 370 | - * @return Payone_Log4php_LoggerLevel The assigned level or null if none is assigned. |
|
| 371 | - */ |
|
| 372 | - public function getLevel() { |
|
| 373 | - return $this->level; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Set the Logger level. |
|
| 378 | - * |
|
| 379 | - * @param Payone_Log4php_LoggerLevel $level the level to set |
|
| 380 | - */ |
|
| 381 | - public function setLevel($level) { |
|
| 382 | - $this->level = $level; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Checks whether an appender is attached to this logger instance. |
|
| 387 | - * |
|
| 388 | - * @param Payone_Log4php_LoggerAppender $appender |
|
| 389 | - * @return boolean |
|
| 390 | - */ |
|
| 391 | - public function isAttached(Payone_Log4php_LoggerAppender $appender) { |
|
| 392 | - return isset($this->appenders[$appender->getName()]); |
|
| 393 | - } |
|
| 368 | + /** |
|
| 369 | + * Get the assigned Logger level. |
|
| 370 | + * @return Payone_Log4php_LoggerLevel The assigned level or null if none is assigned. |
|
| 371 | + */ |
|
| 372 | + public function getLevel() { |
|
| 373 | + return $this->level; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Set the Logger level. |
|
| 378 | + * |
|
| 379 | + * @param Payone_Log4php_LoggerLevel $level the level to set |
|
| 380 | + */ |
|
| 381 | + public function setLevel($level) { |
|
| 382 | + $this->level = $level; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Checks whether an appender is attached to this logger instance. |
|
| 387 | + * |
|
| 388 | + * @param Payone_Log4php_LoggerAppender $appender |
|
| 389 | + * @return boolean |
|
| 390 | + */ |
|
| 391 | + public function isAttached(Payone_Log4php_LoggerAppender $appender) { |
|
| 392 | + return isset($this->appenders[$appender->getName()]); |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | 395 | |
| 396 | - /** |
|
| 397 | - * Sets the parent logger. |
|
| 398 | - * @param Logger $logger |
|
| 399 | - */ |
|
| 400 | - public function setParent(Payone_Log4php_Logger $logger) { |
|
| 401 | - $this->parent = $logger; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // ****************************************** |
|
| 405 | - // *** Static methods and properties *** |
|
| 406 | - // ****************************************** |
|
| 407 | - |
|
| 408 | - /** The logger hierarchy used by log4php. */ |
|
| 409 | - private static $hierarchy; |
|
| 410 | - |
|
| 411 | - /** Inidicates if log4php has been initialized */ |
|
| 412 | - private static $initialized = false; |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * Returns the hierarchy used by this Logger. |
|
| 416 | - * |
|
| 417 | - * Caution: do not use this hierarchy unless you have called initialize(). |
|
| 418 | - * To get Loggers, use the Logger::getLogger and Logger::getRootLogger |
|
| 419 | - * methods instead of operating on on the hierarchy directly. |
|
| 420 | - * |
|
| 421 | - * @return Payone_Log4php_LoggerHierarchy |
|
| 422 | - */ |
|
| 423 | - public static function getHierarchy() { |
|
| 424 | - if(!isset(self::$hierarchy)) { |
|
| 425 | - self::$hierarchy = new Payone_Log4php_LoggerHierarchy(new Payone_Log4php_LoggerRoot()); |
|
| 426 | - } |
|
| 427 | - return self::$hierarchy; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Returns a Logger by name. If it does not exist, it will be created. |
|
| 432 | - * |
|
| 433 | - * @param string $name The logger name |
|
| 434 | - * @return Logger |
|
| 435 | - */ |
|
| 436 | - public static function getLogger($name) { |
|
| 437 | - if(!self::isInitialized()) { |
|
| 438 | - self::configure(); |
|
| 439 | - } |
|
| 440 | - return self::getHierarchy()->getLogger($name); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Returns the Root Logger. |
|
| 445 | - * @return Payone_Log4php_LoggerRoot |
|
| 446 | - */ |
|
| 447 | - public static function getRootLogger() { |
|
| 448 | - if(!self::isInitialized()) { |
|
| 449 | - self::configure(); |
|
| 450 | - } |
|
| 451 | - return self::getHierarchy()->getRootLogger(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * Clears all Logger definitions from the logger hierarchy. |
|
| 456 | - * @return boolean |
|
| 457 | - */ |
|
| 458 | - public static function clear() { |
|
| 459 | - return self::getHierarchy()->clear(); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Destroy configurations for logger definitions |
|
| 464 | - */ |
|
| 465 | - public static function resetConfiguration() { |
|
| 466 | - self::getHierarchy()->resetConfiguration(); |
|
| 467 | - self::getHierarchy()->clear(); // TODO: clear or not? |
|
| 468 | - self::$initialized = false; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - /** |
|
| 472 | - * Safely close all appenders. |
|
| 473 | - * @deprecated This is no longer necessary due the appenders shutdown via |
|
| 474 | - * destructors. |
|
| 475 | - */ |
|
| 476 | - public static function shutdown() { |
|
| 477 | - return self::getHierarchy()->shutdown(); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - /** |
|
| 481 | - * check if a given logger exists. |
|
| 482 | - * |
|
| 483 | - * @param string $name logger name |
|
| 484 | - * @return boolean |
|
| 485 | - */ |
|
| 486 | - public static function exists($name) { |
|
| 487 | - return self::getHierarchy()->exists($name); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * Returns an array this whole Logger instances. |
|
| 492 | - * @see Logger |
|
| 493 | - * @return array |
|
| 494 | - */ |
|
| 495 | - public static function getCurrentLoggers() { |
|
| 496 | - return self::getHierarchy()->getCurrentLoggers(); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Configures log4php. |
|
| 501 | - * |
|
| 502 | - * This method needs to be called before the first logging event has |
|
| 503 | - * occured. If this method is not called before then the default |
|
| 504 | - * configuration will be used. |
|
| 505 | - * |
|
| 506 | - * @param string|array $configuration Either a path to the configuration |
|
| 507 | - * file, or a configuration array. |
|
| 508 | - * |
|
| 509 | - * @param string|LoggerConfigurator $configurator A custom |
|
| 510 | - * configurator class: either a class name (string), or an object which |
|
| 511 | - * implements the LoggerConfigurator interface. If left empty, the default |
|
| 512 | - * configurator implementation will be used. |
|
| 513 | - */ |
|
| 514 | - public static function configure($configuration = null, $configurator = null) { |
|
| 515 | - self::resetConfiguration(); |
|
| 516 | - $configurator = self::getConfigurator($configurator); |
|
| 517 | - $configurator->configure(self::getHierarchy(), $configuration); |
|
| 518 | - self::$initialized = true; |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * Creates a logger configurator instance based on the provided |
|
| 523 | - * configurator class. If no class is given, returns an instance of |
|
| 524 | - * the default configurator. |
|
| 525 | - * |
|
| 526 | - * @param string|LoggerConfigurator $configurator The configurator class |
|
| 527 | - * or LoggerConfigurator instance. |
|
| 528 | - */ |
|
| 529 | - private static function getConfigurator($configurator = null) { |
|
| 530 | - if ($configurator === null) { |
|
| 531 | - return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 532 | - } |
|
| 396 | + /** |
|
| 397 | + * Sets the parent logger. |
|
| 398 | + * @param Logger $logger |
|
| 399 | + */ |
|
| 400 | + public function setParent(Payone_Log4php_Logger $logger) { |
|
| 401 | + $this->parent = $logger; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // ****************************************** |
|
| 405 | + // *** Static methods and properties *** |
|
| 406 | + // ****************************************** |
|
| 407 | + |
|
| 408 | + /** The logger hierarchy used by log4php. */ |
|
| 409 | + private static $hierarchy; |
|
| 410 | + |
|
| 411 | + /** Inidicates if log4php has been initialized */ |
|
| 412 | + private static $initialized = false; |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * Returns the hierarchy used by this Logger. |
|
| 416 | + * |
|
| 417 | + * Caution: do not use this hierarchy unless you have called initialize(). |
|
| 418 | + * To get Loggers, use the Logger::getLogger and Logger::getRootLogger |
|
| 419 | + * methods instead of operating on on the hierarchy directly. |
|
| 420 | + * |
|
| 421 | + * @return Payone_Log4php_LoggerHierarchy |
|
| 422 | + */ |
|
| 423 | + public static function getHierarchy() { |
|
| 424 | + if(!isset(self::$hierarchy)) { |
|
| 425 | + self::$hierarchy = new Payone_Log4php_LoggerHierarchy(new Payone_Log4php_LoggerRoot()); |
|
| 426 | + } |
|
| 427 | + return self::$hierarchy; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Returns a Logger by name. If it does not exist, it will be created. |
|
| 432 | + * |
|
| 433 | + * @param string $name The logger name |
|
| 434 | + * @return Logger |
|
| 435 | + */ |
|
| 436 | + public static function getLogger($name) { |
|
| 437 | + if(!self::isInitialized()) { |
|
| 438 | + self::configure(); |
|
| 439 | + } |
|
| 440 | + return self::getHierarchy()->getLogger($name); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Returns the Root Logger. |
|
| 445 | + * @return Payone_Log4php_LoggerRoot |
|
| 446 | + */ |
|
| 447 | + public static function getRootLogger() { |
|
| 448 | + if(!self::isInitialized()) { |
|
| 449 | + self::configure(); |
|
| 450 | + } |
|
| 451 | + return self::getHierarchy()->getRootLogger(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * Clears all Logger definitions from the logger hierarchy. |
|
| 456 | + * @return boolean |
|
| 457 | + */ |
|
| 458 | + public static function clear() { |
|
| 459 | + return self::getHierarchy()->clear(); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Destroy configurations for logger definitions |
|
| 464 | + */ |
|
| 465 | + public static function resetConfiguration() { |
|
| 466 | + self::getHierarchy()->resetConfiguration(); |
|
| 467 | + self::getHierarchy()->clear(); // TODO: clear or not? |
|
| 468 | + self::$initialized = false; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + /** |
|
| 472 | + * Safely close all appenders. |
|
| 473 | + * @deprecated This is no longer necessary due the appenders shutdown via |
|
| 474 | + * destructors. |
|
| 475 | + */ |
|
| 476 | + public static function shutdown() { |
|
| 477 | + return self::getHierarchy()->shutdown(); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + /** |
|
| 481 | + * check if a given logger exists. |
|
| 482 | + * |
|
| 483 | + * @param string $name logger name |
|
| 484 | + * @return boolean |
|
| 485 | + */ |
|
| 486 | + public static function exists($name) { |
|
| 487 | + return self::getHierarchy()->exists($name); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * Returns an array this whole Logger instances. |
|
| 492 | + * @see Logger |
|
| 493 | + * @return array |
|
| 494 | + */ |
|
| 495 | + public static function getCurrentLoggers() { |
|
| 496 | + return self::getHierarchy()->getCurrentLoggers(); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Configures log4php. |
|
| 501 | + * |
|
| 502 | + * This method needs to be called before the first logging event has |
|
| 503 | + * occured. If this method is not called before then the default |
|
| 504 | + * configuration will be used. |
|
| 505 | + * |
|
| 506 | + * @param string|array $configuration Either a path to the configuration |
|
| 507 | + * file, or a configuration array. |
|
| 508 | + * |
|
| 509 | + * @param string|LoggerConfigurator $configurator A custom |
|
| 510 | + * configurator class: either a class name (string), or an object which |
|
| 511 | + * implements the LoggerConfigurator interface. If left empty, the default |
|
| 512 | + * configurator implementation will be used. |
|
| 513 | + */ |
|
| 514 | + public static function configure($configuration = null, $configurator = null) { |
|
| 515 | + self::resetConfiguration(); |
|
| 516 | + $configurator = self::getConfigurator($configurator); |
|
| 517 | + $configurator->configure(self::getHierarchy(), $configuration); |
|
| 518 | + self::$initialized = true; |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * Creates a logger configurator instance based on the provided |
|
| 523 | + * configurator class. If no class is given, returns an instance of |
|
| 524 | + * the default configurator. |
|
| 525 | + * |
|
| 526 | + * @param string|LoggerConfigurator $configurator The configurator class |
|
| 527 | + * or LoggerConfigurator instance. |
|
| 528 | + */ |
|
| 529 | + private static function getConfigurator($configurator = null) { |
|
| 530 | + if ($configurator === null) { |
|
| 531 | + return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 532 | + } |
|
| 533 | 533 | |
| 534 | - if (is_object($configurator)) { |
|
| 535 | - if ($configurator instanceof Payone_Log4php_LoggerConfigurator) { |
|
| 536 | - return $configurator; |
|
| 537 | - } else { |
|
| 538 | - trigger_error("log4php: Given configurator object [$configurator] does not implement the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING); |
|
| 539 | - return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 540 | - } |
|
| 541 | - } |
|
| 534 | + if (is_object($configurator)) { |
|
| 535 | + if ($configurator instanceof Payone_Log4php_LoggerConfigurator) { |
|
| 536 | + return $configurator; |
|
| 537 | + } else { |
|
| 538 | + trigger_error("log4php: Given configurator object [$configurator] does not implement the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING); |
|
| 539 | + return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | 542 | |
| 543 | - if (is_string($configurator)) { |
|
| 544 | - if (!class_exists($configurator)) { |
|
| 545 | - trigger_error("log4php: Specified configurator class [$configurator] does not exist. Reverting to default configurator.", E_USER_WARNING); |
|
| 546 | - return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 547 | - } |
|
| 543 | + if (is_string($configurator)) { |
|
| 544 | + if (!class_exists($configurator)) { |
|
| 545 | + trigger_error("log4php: Specified configurator class [$configurator] does not exist. Reverting to default configurator.", E_USER_WARNING); |
|
| 546 | + return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 547 | + } |
|
| 548 | 548 | |
| 549 | - $instance = new $configurator(); |
|
| 549 | + $instance = new $configurator(); |
|
| 550 | 550 | |
| 551 | - if (!($instance instanceof Payone_Log4php_LoggerConfigurator)) { |
|
| 552 | - trigger_error("log4php: Specified configurator class [$configurator] does not implement the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING); |
|
| 553 | - return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 554 | - } |
|
| 551 | + if (!($instance instanceof Payone_Log4php_LoggerConfigurator)) { |
|
| 552 | + trigger_error("log4php: Specified configurator class [$configurator] does not implement the LoggerConfigurator interface. Reverting to default configurator.", E_USER_WARNING); |
|
| 553 | + return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 554 | + } |
|
| 555 | 555 | |
| 556 | - return $instance; |
|
| 557 | - } |
|
| 556 | + return $instance; |
|
| 557 | + } |
|
| 558 | 558 | |
| 559 | - trigger_error("log4php: Invalid configurator specified. Expected either a string or a LoggerConfigurator instance. Reverting to default configurator.", E_USER_WARNING); |
|
| 560 | - return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - /** |
|
| 564 | - * Returns true if the log4php framework has been initialized. |
|
| 565 | - * @return boolean |
|
| 566 | - */ |
|
| 567 | - private static function isInitialized() { |
|
| 568 | - return self::$initialized; |
|
| 569 | - } |
|
| 559 | + trigger_error("log4php: Invalid configurator specified. Expected either a string or a LoggerConfigurator instance. Reverting to default configurator.", E_USER_WARNING); |
|
| 560 | + return new Payone_Log4php_LoggerConfiguratorDefault(); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + /** |
|
| 564 | + * Returns true if the log4php framework has been initialized. |
|
| 565 | + * @return boolean |
|
| 566 | + */ |
|
| 567 | + private static function isInitialized() { |
|
| 568 | + return self::$initialized; |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | 571 | } |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * in the logging event. |
| 170 | 170 | */ |
| 171 | 171 | public function log(Payone_Log4php_LoggerLevel $level, $message, $throwable = null) { |
| 172 | - if($this->isEnabledFor($level)) { |
|
| 172 | + if ($this->isEnabledFor($level)) { |
|
| 173 | 173 | $this->forcedLog($this->fqcn, $throwable, $level, $message); |
| 174 | 174 | } |
| 175 | 175 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | * @param string $msg message to log |
| 183 | 183 | */ |
| 184 | 184 | public function assertLog($assertion = true, $msg = '') { |
| 185 | - if($assertion == false) { |
|
| 185 | + if ($assertion == false) { |
|
| 186 | 186 | $this->error($msg); |
| 187 | 187 | } |
| 188 | 188 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | |
| 286 | 286 | /** Removes all appenders from the Logger. */ |
| 287 | 287 | public function removeAllAppenders() { |
| 288 | - foreach($this->appenders as $name => $appender) { |
|
| 288 | + foreach ($this->appenders as $name => $appender) { |
|
| 289 | 289 | $this->removeAppender($name); |
| 290 | 290 | } |
| 291 | 291 | } |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @param mixed $appender an appender name or a {@link Payone_Log4php_LoggerAppender} instance. |
| 296 | 296 | */ |
| 297 | 297 | public function removeAppender($appender) { |
| 298 | - if($appender instanceof Payone_Log4php_LoggerAppender) { |
|
| 298 | + if ($appender instanceof Payone_Log4php_LoggerAppender) { |
|
| 299 | 299 | $appender->close(); |
| 300 | 300 | unset($this->appenders[$appender->getName()]); |
| 301 | 301 | } else if (is_string($appender) and isset($this->appenders[$appender])) { |
@@ -310,12 +310,12 @@ discard block |
||
| 310 | 310 | */ |
| 311 | 311 | public function callAppenders($event) { |
| 312 | 312 | // Forward the event to each linked appender |
| 313 | - foreach($this->appenders as $appender) { |
|
| 313 | + foreach ($this->appenders as $appender) { |
|
| 314 | 314 | $appender->doAppend($event); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | // Forward the event upstream if additivity is turned on |
| 318 | - if(isset($this->parent) && $this->getAdditivity()) { |
|
| 318 | + if (isset($this->parent) && $this->getAdditivity()) { |
|
| 319 | 319 | $this->parent->callAppenders($event); |
| 320 | 320 | } |
| 321 | 321 | } |
@@ -358,8 +358,8 @@ discard block |
||
| 358 | 358 | * @return Payone_Log4php_LoggerLevel or null |
| 359 | 359 | */ |
| 360 | 360 | public function getEffectiveLevel() { |
| 361 | - for($logger = $this; $logger !== null; $logger = $logger->getParent()) { |
|
| 362 | - if($logger->getLevel() !== null) { |
|
| 361 | + for ($logger = $this; $logger !== null; $logger = $logger->getParent()) { |
|
| 362 | + if ($logger->getLevel() !== null) { |
|
| 363 | 363 | return $logger->getLevel(); |
| 364 | 364 | } |
| 365 | 365 | } |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | * @return Payone_Log4php_LoggerHierarchy |
| 422 | 422 | */ |
| 423 | 423 | public static function getHierarchy() { |
| 424 | - if(!isset(self::$hierarchy)) { |
|
| 424 | + if (!isset(self::$hierarchy)) { |
|
| 425 | 425 | self::$hierarchy = new Payone_Log4php_LoggerHierarchy(new Payone_Log4php_LoggerRoot()); |
| 426 | 426 | } |
| 427 | 427 | return self::$hierarchy; |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | * @return Logger |
| 435 | 435 | */ |
| 436 | 436 | public static function getLogger($name) { |
| 437 | - if(!self::isInitialized()) { |
|
| 437 | + if (!self::isInitialized()) { |
|
| 438 | 438 | self::configure(); |
| 439 | 439 | } |
| 440 | 440 | return self::getHierarchy()->getLogger($name); |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | * @return Payone_Log4php_LoggerRoot |
| 446 | 446 | */ |
| 447 | 447 | public static function getRootLogger() { |
| 448 | - if(!self::isInitialized()) { |
|
| 448 | + if (!self::isInitialized()) { |
|
| 449 | 449 | self::configure(); |
| 450 | 450 | } |
| 451 | 451 | return self::getHierarchy()->getRootLogger(); |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | /** |
| 86 | 86 | * Returns the parent Logger. Can be null if this is the root logger. |
| 87 | - * @return Logger |
|
| 87 | + * @return Payone_Log4php_Logger |
|
| 88 | 88 | */ |
| 89 | 89 | public function getParent() { |
| 90 | 90 | return $this->parent; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | /** |
| 142 | 142 | * Log a message object with the ERROR level. |
| 143 | 143 | * |
| 144 | - * @param mixed $message message |
|
| 144 | + * @param string $message message |
|
| 145 | 145 | * @param Exception $throwable Optional throwable information to include |
| 146 | 146 | * in the logging event. |
| 147 | 147 | */ |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | |
| 396 | 396 | /** |
| 397 | 397 | * Sets the parent logger. |
| 398 | - * @param Logger $logger |
|
| 398 | + * @param Payone_Log4php_Logger $logger |
|
| 399 | 399 | */ |
| 400 | 400 | public function setParent(Payone_Log4php_Logger $logger) { |
| 401 | 401 | $this->parent = $logger; |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | /** |
| 455 | 455 | * Clears all Logger definitions from the logger hierarchy. |
| 456 | - * @return boolean |
|
| 456 | + * @return boolean|null |
|
| 457 | 457 | */ |
| 458 | 458 | public static function clear() { |
| 459 | 459 | return self::getHierarchy()->clear(); |
@@ -33,282 +33,282 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Payone_Log4php_LoggerAppenderMongoDB extends Payone_Log4php_LoggerAppender { |
| 35 | 35 | |
| 36 | - // ****************************************** |
|
| 37 | - // ** Constants ** |
|
| 38 | - // ****************************************** |
|
| 36 | + // ****************************************** |
|
| 37 | + // ** Constants ** |
|
| 38 | + // ****************************************** |
|
| 39 | 39 | |
| 40 | - /** Default prefix for the {@link $host}. */ |
|
| 41 | - const DEFAULT_MONGO_URL_PREFIX = 'mongodb://'; |
|
| 40 | + /** Default prefix for the {@link $host}. */ |
|
| 41 | + const DEFAULT_MONGO_URL_PREFIX = 'mongodb://'; |
|
| 42 | 42 | |
| 43 | - /** Default value for {@link $host}, without a prefix. */ |
|
| 44 | - const DEFAULT_MONGO_HOST = 'localhost'; |
|
| 43 | + /** Default value for {@link $host}, without a prefix. */ |
|
| 44 | + const DEFAULT_MONGO_HOST = 'localhost'; |
|
| 45 | 45 | |
| 46 | - /** Default value for {@link $port} */ |
|
| 47 | - const DEFAULT_MONGO_PORT = 27017; |
|
| 46 | + /** Default value for {@link $port} */ |
|
| 47 | + const DEFAULT_MONGO_PORT = 27017; |
|
| 48 | 48 | |
| 49 | - /** Default value for {@link $databaseName} */ |
|
| 50 | - const DEFAULT_DB_NAME = 'log4php_mongodb'; |
|
| 49 | + /** Default value for {@link $databaseName} */ |
|
| 50 | + const DEFAULT_DB_NAME = 'log4php_mongodb'; |
|
| 51 | 51 | |
| 52 | - /** Default value for {@link $collectionName} */ |
|
| 53 | - const DEFAULT_COLLECTION_NAME = 'logs'; |
|
| 52 | + /** Default value for {@link $collectionName} */ |
|
| 53 | + const DEFAULT_COLLECTION_NAME = 'logs'; |
|
| 54 | 54 | |
| 55 | - /** Default value for {@link $timeout} */ |
|
| 56 | - const DEFAULT_TIMEOUT_VALUE = 3000; |
|
| 55 | + /** Default value for {@link $timeout} */ |
|
| 56 | + const DEFAULT_TIMEOUT_VALUE = 3000; |
|
| 57 | 57 | |
| 58 | - // ****************************************** |
|
| 59 | - // ** Configurable parameters ** |
|
| 60 | - // ****************************************** |
|
| 58 | + // ****************************************** |
|
| 59 | + // ** Configurable parameters ** |
|
| 60 | + // ****************************************** |
|
| 61 | 61 | |
| 62 | - /** Server on which mongodb instance is located. */ |
|
| 63 | - protected $host; |
|
| 62 | + /** Server on which mongodb instance is located. */ |
|
| 63 | + protected $host; |
|
| 64 | 64 | |
| 65 | - /** Port on which the instance is bound. */ |
|
| 66 | - protected $port; |
|
| 65 | + /** Port on which the instance is bound. */ |
|
| 66 | + protected $port; |
|
| 67 | 67 | |
| 68 | - /** Name of the database to which to log. */ |
|
| 69 | - protected $databaseName; |
|
| 68 | + /** Name of the database to which to log. */ |
|
| 69 | + protected $databaseName; |
|
| 70 | 70 | |
| 71 | - /** Name of the collection within the given database. */ |
|
| 72 | - protected $collectionName; |
|
| 71 | + /** Name of the collection within the given database. */ |
|
| 72 | + protected $collectionName; |
|
| 73 | 73 | |
| 74 | - /** Username used to connect to the database. */ |
|
| 75 | - protected $userName; |
|
| 74 | + /** Username used to connect to the database. */ |
|
| 75 | + protected $userName; |
|
| 76 | 76 | |
| 77 | - /** Password used to connect to the database. */ |
|
| 78 | - protected $password; |
|
| 77 | + /** Password used to connect to the database. */ |
|
| 78 | + protected $password; |
|
| 79 | 79 | |
| 80 | - /** Timeout value used when connecting to the database (in milliseconds). */ |
|
| 81 | - protected $timeout; |
|
| 80 | + /** Timeout value used when connecting to the database (in milliseconds). */ |
|
| 81 | + protected $timeout; |
|
| 82 | 82 | |
| 83 | - // ****************************************** |
|
| 84 | - // ** Member variables ** |
|
| 85 | - // ****************************************** |
|
| 83 | + // ****************************************** |
|
| 84 | + // ** Member variables ** |
|
| 85 | + // ****************************************** |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Connection to the MongoDB instance. |
|
| 89 | - * @var Mongo |
|
| 90 | - */ |
|
| 91 | - protected $connection; |
|
| 87 | + /** |
|
| 88 | + * Connection to the MongoDB instance. |
|
| 89 | + * @var Mongo |
|
| 90 | + */ |
|
| 91 | + protected $connection; |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * The collection to which log is written. |
|
| 95 | - * @var MongoCollection |
|
| 96 | - */ |
|
| 97 | - protected $collection; |
|
| 93 | + /** |
|
| 94 | + * The collection to which log is written. |
|
| 95 | + * @var MongoCollection |
|
| 96 | + */ |
|
| 97 | + protected $collection; |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Set to true if the appender can append. |
|
| 101 | - * @todo Maybe we should use $closed here instead? |
|
| 102 | - */ |
|
| 103 | - protected $canAppend = false; |
|
| 99 | + /** |
|
| 100 | + * Set to true if the appender can append. |
|
| 101 | + * @todo Maybe we should use $closed here instead? |
|
| 102 | + */ |
|
| 103 | + protected $canAppend = false; |
|
| 104 | 104 | |
| 105 | - /** Appender does not require a layout. */ |
|
| 106 | - protected $requiresLayout = false; |
|
| 105 | + /** Appender does not require a layout. */ |
|
| 106 | + protected $requiresLayout = false; |
|
| 107 | 107 | |
| 108 | - public function __construct($name = '') { |
|
| 109 | - parent::__construct($name); |
|
| 110 | - $this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST; |
|
| 111 | - $this->port = self::DEFAULT_MONGO_PORT; |
|
| 112 | - $this->databaseName = self::DEFAULT_DB_NAME; |
|
| 113 | - $this->collectionName = self::DEFAULT_COLLECTION_NAME; |
|
| 114 | - $this->timeout = self::DEFAULT_TIMEOUT_VALUE; |
|
| 115 | - } |
|
| 108 | + public function __construct($name = '') { |
|
| 109 | + parent::__construct($name); |
|
| 110 | + $this->host = self::DEFAULT_MONGO_URL_PREFIX . self::DEFAULT_MONGO_HOST; |
|
| 111 | + $this->port = self::DEFAULT_MONGO_PORT; |
|
| 112 | + $this->databaseName = self::DEFAULT_DB_NAME; |
|
| 113 | + $this->collectionName = self::DEFAULT_COLLECTION_NAME; |
|
| 114 | + $this->timeout = self::DEFAULT_TIMEOUT_VALUE; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Setup db connection. |
|
| 119 | - * Based on defined options, this method connects to the database and |
|
| 120 | - * creates a {@link $collection}. |
|
| 121 | - * |
|
| 122 | - * @throws Exception if the attempt to connect to the requested database fails. |
|
| 123 | - */ |
|
| 124 | - public function activateOptions() { |
|
| 125 | - try { |
|
| 126 | - $this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array("timeout" => $this->timeout)); |
|
| 127 | - $db = $this->connection->selectDB($this->databaseName); |
|
| 128 | - if ($this->userName !== null && $this->password !== null) { |
|
| 129 | - $authResult = $db->authenticate($this->userName, $this->password); |
|
| 130 | - if ($authResult['ok'] == floatval(0)) { |
|
| 131 | - throw new Exception($authResult['errmsg'], $authResult['ok']); |
|
| 132 | - } |
|
| 133 | - } |
|
| 117 | + /** |
|
| 118 | + * Setup db connection. |
|
| 119 | + * Based on defined options, this method connects to the database and |
|
| 120 | + * creates a {@link $collection}. |
|
| 121 | + * |
|
| 122 | + * @throws Exception if the attempt to connect to the requested database fails. |
|
| 123 | + */ |
|
| 124 | + public function activateOptions() { |
|
| 125 | + try { |
|
| 126 | + $this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array("timeout" => $this->timeout)); |
|
| 127 | + $db = $this->connection->selectDB($this->databaseName); |
|
| 128 | + if ($this->userName !== null && $this->password !== null) { |
|
| 129 | + $authResult = $db->authenticate($this->userName, $this->password); |
|
| 130 | + if ($authResult['ok'] == floatval(0)) { |
|
| 131 | + throw new Exception($authResult['errmsg'], $authResult['ok']); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $this->collection = $db->selectCollection($this->collectionName); |
|
| 136 | - } catch (Exception $ex) { |
|
| 137 | - $this->canAppend = false; |
|
| 138 | - throw new Payone_Log4php_LoggerException($ex); |
|
| 139 | - } |
|
| 135 | + $this->collection = $db->selectCollection($this->collectionName); |
|
| 136 | + } catch (Exception $ex) { |
|
| 137 | + $this->canAppend = false; |
|
| 138 | + throw new Payone_Log4php_LoggerException($ex); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $this->canAppend = true; |
|
| 142 | - } |
|
| 141 | + $this->canAppend = true; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Appends a new event to the mongo database. |
|
| 146 | - * |
|
| 147 | - * @throws LoggerException If the pattern conversion or the INSERT statement fails. |
|
| 148 | - */ |
|
| 149 | - public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 150 | - if ($this->canAppend == true && $this->collection != null) { |
|
| 151 | - $document = $this->format($event); |
|
| 152 | - $this->collection->insert($document); |
|
| 153 | - } |
|
| 154 | - } |
|
| 144 | + /** |
|
| 145 | + * Appends a new event to the mongo database. |
|
| 146 | + * |
|
| 147 | + * @throws LoggerException If the pattern conversion or the INSERT statement fails. |
|
| 148 | + */ |
|
| 149 | + public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 150 | + if ($this->canAppend == true && $this->collection != null) { |
|
| 151 | + $document = $this->format($event); |
|
| 152 | + $this->collection->insert($document); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Converts the logging event into an array which can be logged to mongodb. |
|
| 158 | - * |
|
| 159 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 160 | - * @return array The array representation of the logging event. |
|
| 161 | - */ |
|
| 162 | - protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 163 | - $timestampSec = (int) $event->getTimestamp(); |
|
| 164 | - $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000); |
|
| 156 | + /** |
|
| 157 | + * Converts the logging event into an array which can be logged to mongodb. |
|
| 158 | + * |
|
| 159 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 160 | + * @return array The array representation of the logging event. |
|
| 161 | + */ |
|
| 162 | + protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 163 | + $timestampSec = (int) $event->getTimestamp(); |
|
| 164 | + $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000); |
|
| 165 | 165 | |
| 166 | - $document = array( |
|
| 167 | - 'timestamp' => new MongoDate($timestampSec, $timestampUsec), |
|
| 168 | - 'level' => $event->getLevel()->toString(), |
|
| 169 | - 'thread' => (int) $event->getThreadName(), |
|
| 170 | - 'message' => $event->getMessage(), |
|
| 171 | - 'loggerName' => $event->getLoggerName() |
|
| 172 | - ); |
|
| 166 | + $document = array( |
|
| 167 | + 'timestamp' => new MongoDate($timestampSec, $timestampUsec), |
|
| 168 | + 'level' => $event->getLevel()->toString(), |
|
| 169 | + 'thread' => (int) $event->getThreadName(), |
|
| 170 | + 'message' => $event->getMessage(), |
|
| 171 | + 'loggerName' => $event->getLoggerName() |
|
| 172 | + ); |
|
| 173 | 173 | |
| 174 | - $locationInfo = $event->getLocationInformation(); |
|
| 175 | - if ($locationInfo != null) { |
|
| 176 | - $document['fileName'] = $locationInfo->getFileName(); |
|
| 177 | - $document['method'] = $locationInfo->getMethodName(); |
|
| 178 | - $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber(); |
|
| 179 | - $document['className'] = $locationInfo->getClassName(); |
|
| 180 | - } |
|
| 174 | + $locationInfo = $event->getLocationInformation(); |
|
| 175 | + if ($locationInfo != null) { |
|
| 176 | + $document['fileName'] = $locationInfo->getFileName(); |
|
| 177 | + $document['method'] = $locationInfo->getMethodName(); |
|
| 178 | + $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber(); |
|
| 179 | + $document['className'] = $locationInfo->getClassName(); |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - $throwableInfo = $event->getThrowableInformation(); |
|
| 183 | - if ($throwableInfo != null) { |
|
| 184 | - $document['exception'] = $this->formatThrowable($throwableInfo->getThrowable()); |
|
| 185 | - } |
|
| 182 | + $throwableInfo = $event->getThrowableInformation(); |
|
| 183 | + if ($throwableInfo != null) { |
|
| 184 | + $document['exception'] = $this->formatThrowable($throwableInfo->getThrowable()); |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - return $document; |
|
| 188 | - } |
|
| 187 | + return $document; |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * Converts an Exception into an array which can be logged to mongodb. |
|
| 192 | - * |
|
| 193 | - * Supports innner exceptions (PHP >= 5.3) |
|
| 194 | - * |
|
| 195 | - * @param Exception $ex |
|
| 196 | - * @return array |
|
| 197 | - */ |
|
| 198 | - protected function formatThrowable(Exception $ex) { |
|
| 199 | - $array = array( |
|
| 200 | - 'message' => $ex->getMessage(), |
|
| 201 | - 'code' => $ex->getCode(), |
|
| 202 | - 'stackTrace' => $ex->getTraceAsString(), |
|
| 203 | - ); |
|
| 190 | + /** |
|
| 191 | + * Converts an Exception into an array which can be logged to mongodb. |
|
| 192 | + * |
|
| 193 | + * Supports innner exceptions (PHP >= 5.3) |
|
| 194 | + * |
|
| 195 | + * @param Exception $ex |
|
| 196 | + * @return array |
|
| 197 | + */ |
|
| 198 | + protected function formatThrowable(Exception $ex) { |
|
| 199 | + $array = array( |
|
| 200 | + 'message' => $ex->getMessage(), |
|
| 201 | + 'code' => $ex->getCode(), |
|
| 202 | + 'stackTrace' => $ex->getTraceAsString(), |
|
| 203 | + ); |
|
| 204 | 204 | |
| 205 | - if (method_exists($ex, 'getPrevious') && $ex->getPrevious() !== null) { |
|
| 206 | - $array['innerException'] = $this->formatThrowable($ex->getPrevious()); |
|
| 207 | - } |
|
| 205 | + if (method_exists($ex, 'getPrevious') && $ex->getPrevious() !== null) { |
|
| 206 | + $array['innerException'] = $this->formatThrowable($ex->getPrevious()); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return $array; |
|
| 210 | - } |
|
| 209 | + return $array; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Closes the connection to the logging database |
|
| 214 | - */ |
|
| 215 | - public function close() { |
|
| 216 | - if($this->closed != true) { |
|
| 217 | - $this->collection = null; |
|
| 218 | - if ($this->connection !== null) { |
|
| 219 | - $this->connection->close(); |
|
| 220 | - $this->connection = null; |
|
| 221 | - } |
|
| 222 | - $this->closed = true; |
|
| 223 | - } |
|
| 224 | - } |
|
| 212 | + /** |
|
| 213 | + * Closes the connection to the logging database |
|
| 214 | + */ |
|
| 215 | + public function close() { |
|
| 216 | + if($this->closed != true) { |
|
| 217 | + $this->collection = null; |
|
| 218 | + if ($this->connection !== null) { |
|
| 219 | + $this->connection->close(); |
|
| 220 | + $this->connection = null; |
|
| 221 | + } |
|
| 222 | + $this->closed = true; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** Sets the value of {@link $host} parameter. */ |
|
| 227 | - public function setHost($host) { |
|
| 228 | - if (!preg_match('/^mongodb\:\/\//', $host)) { |
|
| 229 | - $host = self::DEFAULT_MONGO_URL_PREFIX . $host; |
|
| 230 | - } |
|
| 231 | - $this->host = $host; |
|
| 232 | - } |
|
| 226 | + /** Sets the value of {@link $host} parameter. */ |
|
| 227 | + public function setHost($host) { |
|
| 228 | + if (!preg_match('/^mongodb\:\/\//', $host)) { |
|
| 229 | + $host = self::DEFAULT_MONGO_URL_PREFIX . $host; |
|
| 230 | + } |
|
| 231 | + $this->host = $host; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** Returns the value of {@link $host} parameter. */ |
|
| 235 | - public function getHost() { |
|
| 236 | - return $this->host; |
|
| 237 | - } |
|
| 234 | + /** Returns the value of {@link $host} parameter. */ |
|
| 235 | + public function getHost() { |
|
| 236 | + return $this->host; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** Sets the value of {@link $port} parameter. */ |
|
| 240 | - public function setPort($port) { |
|
| 241 | - $this->setPositiveInteger('port', $port); |
|
| 242 | - } |
|
| 239 | + /** Sets the value of {@link $port} parameter. */ |
|
| 240 | + public function setPort($port) { |
|
| 241 | + $this->setPositiveInteger('port', $port); |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** Returns the value of {@link $port} parameter. */ |
|
| 245 | - public function getPort() { |
|
| 246 | - return $this->port; |
|
| 247 | - } |
|
| 244 | + /** Returns the value of {@link $port} parameter. */ |
|
| 245 | + public function getPort() { |
|
| 246 | + return $this->port; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** Sets the value of {@link $databaseName} parameter. */ |
|
| 250 | - public function setDatabaseName($databaseName) { |
|
| 251 | - $this->setString('databaseName', $databaseName); |
|
| 252 | - } |
|
| 249 | + /** Sets the value of {@link $databaseName} parameter. */ |
|
| 250 | + public function setDatabaseName($databaseName) { |
|
| 251 | + $this->setString('databaseName', $databaseName); |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** Returns the value of {@link $databaseName} parameter. */ |
|
| 255 | - public function getDatabaseName() { |
|
| 256 | - return $this->databaseName; |
|
| 257 | - } |
|
| 254 | + /** Returns the value of {@link $databaseName} parameter. */ |
|
| 255 | + public function getDatabaseName() { |
|
| 256 | + return $this->databaseName; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** Sets the value of {@link $collectionName} parameter. */ |
|
| 260 | - public function setCollectionName($collectionName) { |
|
| 261 | - $this->setString('collectionName', $collectionName); |
|
| 262 | - } |
|
| 259 | + /** Sets the value of {@link $collectionName} parameter. */ |
|
| 260 | + public function setCollectionName($collectionName) { |
|
| 261 | + $this->setString('collectionName', $collectionName); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - /** Returns the value of {@link $collectionName} parameter. */ |
|
| 265 | - public function getCollectionName() { |
|
| 266 | - return $this->collectionName; |
|
| 267 | - } |
|
| 264 | + /** Returns the value of {@link $collectionName} parameter. */ |
|
| 265 | + public function getCollectionName() { |
|
| 266 | + return $this->collectionName; |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** Sets the value of {@link $userName} parameter. */ |
|
| 270 | - public function setUserName($userName) { |
|
| 271 | - $this->setString('userName', $userName, true); |
|
| 272 | - } |
|
| 269 | + /** Sets the value of {@link $userName} parameter. */ |
|
| 270 | + public function setUserName($userName) { |
|
| 271 | + $this->setString('userName', $userName, true); |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** Returns the value of {@link $userName} parameter. */ |
|
| 275 | - public function getUserName() { |
|
| 276 | - return $this->userName; |
|
| 277 | - } |
|
| 274 | + /** Returns the value of {@link $userName} parameter. */ |
|
| 275 | + public function getUserName() { |
|
| 276 | + return $this->userName; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** Sets the value of {@link $password} parameter. */ |
|
| 280 | - public function setPassword($password) { |
|
| 281 | - $this->setString('password', $password, true); |
|
| 282 | - } |
|
| 279 | + /** Sets the value of {@link $password} parameter. */ |
|
| 280 | + public function setPassword($password) { |
|
| 281 | + $this->setString('password', $password, true); |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** Returns the value of {@link $password} parameter. */ |
|
| 285 | - public function getPassword() { |
|
| 286 | - return $this->password; |
|
| 287 | - } |
|
| 284 | + /** Returns the value of {@link $password} parameter. */ |
|
| 285 | + public function getPassword() { |
|
| 286 | + return $this->password; |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** Sets the value of {@link $timeout} parameter. */ |
|
| 290 | - public function setTimeout($timeout) { |
|
| 291 | - $this->setPositiveInteger('timeout', $timeout); |
|
| 292 | - } |
|
| 289 | + /** Sets the value of {@link $timeout} parameter. */ |
|
| 290 | + public function setTimeout($timeout) { |
|
| 291 | + $this->setPositiveInteger('timeout', $timeout); |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** Returns the value of {@link $timeout} parameter. */ |
|
| 295 | - public function getTimeout() { |
|
| 296 | - return $this->timeout; |
|
| 297 | - } |
|
| 298 | - /** |
|
| 299 | - * Returns the mongodb connection. |
|
| 300 | - * @return Mongo |
|
| 301 | - */ |
|
| 302 | - public function getConnection() { |
|
| 303 | - return $this->connection; |
|
| 304 | - } |
|
| 294 | + /** Returns the value of {@link $timeout} parameter. */ |
|
| 295 | + public function getTimeout() { |
|
| 296 | + return $this->timeout; |
|
| 297 | + } |
|
| 298 | + /** |
|
| 299 | + * Returns the mongodb connection. |
|
| 300 | + * @return Mongo |
|
| 301 | + */ |
|
| 302 | + public function getConnection() { |
|
| 303 | + return $this->connection; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Returns the active mongodb collection. |
|
| 308 | - * @return MongoCollection |
|
| 309 | - */ |
|
| 310 | - public function getCollection() { |
|
| 311 | - return $this->collection; |
|
| 312 | - } |
|
| 306 | + /** |
|
| 307 | + * Returns the active mongodb collection. |
|
| 308 | + * @return MongoCollection |
|
| 309 | + */ |
|
| 310 | + public function getCollection() { |
|
| 311 | + return $this->collection; |
|
| 312 | + } |
|
| 313 | 313 | } |
| 314 | 314 | ?> |
| 315 | 315 | \ No newline at end of file |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | public function activateOptions() { |
| 125 | 125 | try { |
| 126 | 126 | $this->connection = new Mongo(sprintf('%s:%d', $this->host, $this->port), array("timeout" => $this->timeout)); |
| 127 | - $db = $this->connection->selectDB($this->databaseName); |
|
| 127 | + $db = $this->connection->selectDB($this->databaseName); |
|
| 128 | 128 | if ($this->userName !== null && $this->password !== null) { |
| 129 | 129 | $authResult = $db->authenticate($this->userName, $this->password); |
| 130 | 130 | if ($authResult['ok'] == floatval(0)) { |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | * @return array The array representation of the logging event. |
| 161 | 161 | */ |
| 162 | 162 | protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
| 163 | - $timestampSec = (int) $event->getTimestamp(); |
|
| 164 | - $timestampUsec = (int) (($event->getTimestamp() - $timestampSec) * 1000000); |
|
| 163 | + $timestampSec = (int)$event->getTimestamp(); |
|
| 164 | + $timestampUsec = (int)(($event->getTimestamp() - $timestampSec) * 1000000); |
|
| 165 | 165 | |
| 166 | 166 | $document = array( |
| 167 | 167 | 'timestamp' => new MongoDate($timestampSec, $timestampUsec), |
| 168 | 168 | 'level' => $event->getLevel()->toString(), |
| 169 | - 'thread' => (int) $event->getThreadName(), |
|
| 169 | + 'thread' => (int)$event->getThreadName(), |
|
| 170 | 170 | 'message' => $event->getMessage(), |
| 171 | 171 | 'loggerName' => $event->getLoggerName() |
| 172 | 172 | ); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | if ($locationInfo != null) { |
| 176 | 176 | $document['fileName'] = $locationInfo->getFileName(); |
| 177 | 177 | $document['method'] = $locationInfo->getMethodName(); |
| 178 | - $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int) $locationInfo->getLineNumber(); |
|
| 178 | + $document['lineNumber'] = ($locationInfo->getLineNumber() == 'NA') ? 'NA' : (int)$locationInfo->getLineNumber(); |
|
| 179 | 179 | $document['className'] = $locationInfo->getClassName(); |
| 180 | 180 | } |
| 181 | 181 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | * Closes the connection to the logging database |
| 214 | 214 | */ |
| 215 | 215 | public function close() { |
| 216 | - if($this->closed != true) { |
|
| 216 | + if ($this->closed != true) { |
|
| 217 | 217 | $this->collection = null; |
| 218 | 218 | if ($this->connection !== null) { |
| 219 | 219 | $this->connection->close(); |