@@ -36,114 +36,114 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Payone_Log4php_LoggerRendererMap { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $map; |
|
| 39 | + /** |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $map; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var LoggerDefaultRenderer |
|
| 46 | - */ |
|
| 47 | - private $defaultRenderer; |
|
| 44 | + /** |
|
| 45 | + * @var LoggerDefaultRenderer |
|
| 46 | + */ |
|
| 47 | + private $defaultRenderer; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor |
|
| 51 | - */ |
|
| 52 | - public function __construct() { |
|
| 53 | - $this->map = array(); |
|
| 54 | - $this->defaultRenderer = new Payone_Log4php_LoggerRendererDefault(); |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor |
|
| 51 | + */ |
|
| 52 | + public function __construct() { |
|
| 53 | + $this->map = array(); |
|
| 54 | + $this->defaultRenderer = new Payone_Log4php_LoggerRendererDefault(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Add a renderer to a hierarchy passed as parameter. |
|
| 59 | - * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
| 60 | - * |
|
| 61 | - * @param Payone_Log4php_LoggerHierarchy $repository a logger repository. |
|
| 62 | - * @param string $renderedClassName |
|
| 63 | - * @param string $renderingClassName |
|
| 64 | - */ |
|
| 65 | - public function addRenderer($renderedClassName, $renderingClassName) { |
|
| 66 | - $renderer = Payone_Log4php_LoggerReflectionUtils::createObject($renderingClassName); |
|
| 67 | - if($renderer == null) { |
|
| 68 | - return; |
|
| 69 | - } else { |
|
| 70 | - $this->put($renderedClassName, $renderer); |
|
| 71 | - } |
|
| 72 | - } |
|
| 57 | + /** |
|
| 58 | + * Add a renderer to a hierarchy passed as parameter. |
|
| 59 | + * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
| 60 | + * |
|
| 61 | + * @param Payone_Log4php_LoggerHierarchy $repository a logger repository. |
|
| 62 | + * @param string $renderedClassName |
|
| 63 | + * @param string $renderingClassName |
|
| 64 | + */ |
|
| 65 | + public function addRenderer($renderedClassName, $renderingClassName) { |
|
| 66 | + $renderer = Payone_Log4php_LoggerReflectionUtils::createObject($renderingClassName); |
|
| 67 | + if($renderer == null) { |
|
| 68 | + return; |
|
| 69 | + } else { |
|
| 70 | + $this->put($renderedClassName, $renderer); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Find the appropriate renderer for the class type of the |
|
| 77 | - * <var>o</var> parameter. |
|
| 78 | - * |
|
| 79 | - * This is accomplished by calling the {@link getByObject()} |
|
| 80 | - * method if <var>o</var> is object or using {@link Payone_Log4php_LoggerRendererDefault}. |
|
| 81 | - * Once a renderer is found, it is applied on the object <var>o</var> and |
|
| 82 | - * the result is returned as a string. |
|
| 83 | - * |
|
| 84 | - * @param mixed $o |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function findAndRender($o) { |
|
| 88 | - if($o == null) { |
|
| 89 | - return null; |
|
| 90 | - } else { |
|
| 91 | - if(is_object($o)) { |
|
| 92 | - $renderer = $this->getByObject($o); |
|
| 93 | - if($renderer !== null) { |
|
| 94 | - return $renderer->render($o); |
|
| 95 | - } else { |
|
| 96 | - return null; |
|
| 97 | - } |
|
| 98 | - } else { |
|
| 99 | - $renderer = $this->defaultRenderer; |
|
| 100 | - return $renderer->render($o); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 75 | + /** |
|
| 76 | + * Find the appropriate renderer for the class type of the |
|
| 77 | + * <var>o</var> parameter. |
|
| 78 | + * |
|
| 79 | + * This is accomplished by calling the {@link getByObject()} |
|
| 80 | + * method if <var>o</var> is object or using {@link Payone_Log4php_LoggerRendererDefault}. |
|
| 81 | + * Once a renderer is found, it is applied on the object <var>o</var> and |
|
| 82 | + * the result is returned as a string. |
|
| 83 | + * |
|
| 84 | + * @param mixed $o |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function findAndRender($o) { |
|
| 88 | + if($o == null) { |
|
| 89 | + return null; |
|
| 90 | + } else { |
|
| 91 | + if(is_object($o)) { |
|
| 92 | + $renderer = $this->getByObject($o); |
|
| 93 | + if($renderer !== null) { |
|
| 94 | + return $renderer->render($o); |
|
| 95 | + } else { |
|
| 96 | + return null; |
|
| 97 | + } |
|
| 98 | + } else { |
|
| 99 | + $renderer = $this->defaultRenderer; |
|
| 100 | + return $renderer->render($o); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
| 107 | - * class of the object parameter. |
|
| 108 | - * |
|
| 109 | - * @param mixed $o |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function getByObject($o) { |
|
| 113 | - return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
| 114 | - } |
|
| 105 | + /** |
|
| 106 | + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
| 107 | + * class of the object parameter. |
|
| 108 | + * |
|
| 109 | + * @param mixed $o |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function getByObject($o) { |
|
| 113 | + return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Search the parents of <var>clazz</var> for a renderer. |
|
| 119 | - * |
|
| 120 | - * The renderer closest in the hierarchy will be returned. If no |
|
| 121 | - * renderers could be found, then the default renderer is returned. |
|
| 122 | - * |
|
| 123 | - * @param string $class |
|
| 124 | - * @return Payone_Log4php_LoggerRendererObject |
|
| 125 | - */ |
|
| 126 | - public function getByClassName($class) { |
|
| 127 | - $r = null; |
|
| 128 | - for($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 129 | - $c = strtolower($c); |
|
| 130 | - if(isset($this->map[$c])) { |
|
| 131 | - return $this->map[$c]; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $this->defaultRenderer; |
|
| 135 | - } |
|
| 117 | + /** |
|
| 118 | + * Search the parents of <var>clazz</var> for a renderer. |
|
| 119 | + * |
|
| 120 | + * The renderer closest in the hierarchy will be returned. If no |
|
| 121 | + * renderers could be found, then the default renderer is returned. |
|
| 122 | + * |
|
| 123 | + * @param string $class |
|
| 124 | + * @return Payone_Log4php_LoggerRendererObject |
|
| 125 | + */ |
|
| 126 | + public function getByClassName($class) { |
|
| 127 | + $r = null; |
|
| 128 | + for($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 129 | + $c = strtolower($c); |
|
| 130 | + if(isset($this->map[$c])) { |
|
| 131 | + return $this->map[$c]; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $this->defaultRenderer; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - public function clear() { |
|
| 138 | - $this->map = array(); |
|
| 139 | - } |
|
| 137 | + public function clear() { |
|
| 138 | + $this->map = array(); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Register a {@link Payone_Log4php_LoggerRendererObject} for <var>clazz</var>. |
|
| 143 | - * @param string $class |
|
| 144 | - * @param Payone_Log4php_LoggerRendererObject $or |
|
| 145 | - */ |
|
| 146 | - private function put($class, $or) { |
|
| 147 | - $this->map[strtolower($class)] = $or; |
|
| 148 | - } |
|
| 141 | + /** |
|
| 142 | + * Register a {@link Payone_Log4php_LoggerRendererObject} for <var>clazz</var>. |
|
| 143 | + * @param string $class |
|
| 144 | + * @param Payone_Log4php_LoggerRendererObject $or |
|
| 145 | + */ |
|
| 146 | + private function put($class, $or) { |
|
| 147 | + $this->map[strtolower($class)] = $or; |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -26,45 +26,45 @@ |
||
| 26 | 26 | * @see Logger |
| 27 | 27 | */ |
| 28 | 28 | class Payone_Log4php_LoggerRoot extends Payone_Log4php_Logger { |
| 29 | - /** |
|
| 30 | - * Constructor |
|
| 31 | - * |
|
| 32 | - * @param integer $level initial log level |
|
| 33 | - */ |
|
| 34 | - public function __construct($level = null) { |
|
| 35 | - parent::__construct('root'); |
|
| 29 | + /** |
|
| 30 | + * Constructor |
|
| 31 | + * |
|
| 32 | + * @param integer $level initial log level |
|
| 33 | + */ |
|
| 34 | + public function __construct($level = null) { |
|
| 35 | + parent::__construct('root'); |
|
| 36 | 36 | |
| 37 | - if($level == null) { |
|
| 38 | - $level = Payone_Log4php_LoggerLevel::getLevelAll(); |
|
| 39 | - } |
|
| 40 | - $this->setLevel($level); |
|
| 41 | - } |
|
| 37 | + if($level == null) { |
|
| 38 | + $level = Payone_Log4php_LoggerLevel::getLevelAll(); |
|
| 39 | + } |
|
| 40 | + $this->setLevel($level); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return Payone_Log4php_LoggerLevel the level |
|
| 45 | - */ |
|
| 46 | - public function getChainedLevel() { |
|
| 47 | - return parent::getLevel(); |
|
| 48 | - } |
|
| 43 | + /** |
|
| 44 | + * @return Payone_Log4php_LoggerLevel the level |
|
| 45 | + */ |
|
| 46 | + public function getChainedLevel() { |
|
| 47 | + return parent::getLevel(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Setting a null value to the level of the root category may have catastrophic results. |
|
| 52 | - * @param Payone_Log4php_LoggerLevel $level |
|
| 53 | - */ |
|
| 54 | - public function setLevel($level) { |
|
| 55 | - if($level != null) { |
|
| 56 | - parent::setLevel($level); |
|
| 57 | - } |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Setting a null value to the level of the root category may have catastrophic results. |
|
| 52 | + * @param Payone_Log4php_LoggerLevel $level |
|
| 53 | + */ |
|
| 54 | + public function setLevel($level) { |
|
| 55 | + if($level != null) { |
|
| 56 | + parent::setLevel($level); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Always returns false. |
|
| 62 | - * Because LoggerRoot has no parents, it returns false. |
|
| 63 | - * @param Logger $parent |
|
| 64 | - * @return boolean |
|
| 65 | - */ |
|
| 66 | - public function setParent(Payone_Log4php_Logger $parent) { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 60 | + /** |
|
| 61 | + * Always returns false. |
|
| 62 | + * Because LoggerRoot has no parents, it returns false. |
|
| 63 | + * @param Logger $parent |
|
| 64 | + * @return boolean |
|
| 65 | + */ |
|
| 66 | + public function setParent(Payone_Log4php_Logger $parent) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -95,109 +95,109 @@ |
||
| 95 | 95 | */ |
| 96 | 96 | class Payone_Log4php_LoggerNDC { |
| 97 | 97 | |
| 98 | - /** This is the repository of NDC stack */ |
|
| 99 | - private static $stack = array(); |
|
| 98 | + /** This is the repository of NDC stack */ |
|
| 99 | + private static $stack = array(); |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Clear any nested diagnostic information if any. This method is |
|
| 103 | - * useful in cases where the same thread can be potentially used |
|
| 104 | - * over and over in different unrelated contexts. |
|
| 105 | - * |
|
| 106 | - * <p>This method is equivalent to calling the {@link setMaxDepth()} |
|
| 107 | - * method with a zero <var>maxDepth</var> argument. |
|
| 108 | - */ |
|
| 109 | - public static function clear() { |
|
| 110 | - self::$stack = array(); |
|
| 111 | - } |
|
| 101 | + /** |
|
| 102 | + * Clear any nested diagnostic information if any. This method is |
|
| 103 | + * useful in cases where the same thread can be potentially used |
|
| 104 | + * over and over in different unrelated contexts. |
|
| 105 | + * |
|
| 106 | + * <p>This method is equivalent to calling the {@link setMaxDepth()} |
|
| 107 | + * method with a zero <var>maxDepth</var> argument. |
|
| 108 | + */ |
|
| 109 | + public static function clear() { |
|
| 110 | + self::$stack = array(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - public static function get() { |
|
| 118 | - return implode(' ', self::$stack); |
|
| 119 | - } |
|
| 113 | + /** |
|
| 114 | + * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + public static function get() { |
|
| 118 | + return implode(' ', self::$stack); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Get the current nesting depth of this diagnostic context. |
|
| 123 | - * |
|
| 124 | - * @see setMaxDepth() |
|
| 125 | - * @return integer |
|
| 126 | - */ |
|
| 127 | - public static function getDepth() { |
|
| 128 | - return count(self::$stack); |
|
| 129 | - } |
|
| 121 | + /** |
|
| 122 | + * Get the current nesting depth of this diagnostic context. |
|
| 123 | + * |
|
| 124 | + * @see setMaxDepth() |
|
| 125 | + * @return integer |
|
| 126 | + */ |
|
| 127 | + public static function getDepth() { |
|
| 128 | + return count(self::$stack); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Clients should call this method before leaving a diagnostic |
|
| 133 | - * context. |
|
| 134 | - * |
|
| 135 | - * <p>The returned value is the value that was pushed last. If no |
|
| 136 | - * context is available, then the empty string "" is returned.</p> |
|
| 137 | - * |
|
| 138 | - * @return string The innermost diagnostic context. |
|
| 139 | - */ |
|
| 140 | - public static function pop() { |
|
| 141 | - if(count(self::$stack) > 0) { |
|
| 142 | - return array_pop(self::$stack); |
|
| 143 | - } else { |
|
| 144 | - return ''; |
|
| 145 | - } |
|
| 146 | - } |
|
| 131 | + /** |
|
| 132 | + * Clients should call this method before leaving a diagnostic |
|
| 133 | + * context. |
|
| 134 | + * |
|
| 135 | + * <p>The returned value is the value that was pushed last. If no |
|
| 136 | + * context is available, then the empty string "" is returned.</p> |
|
| 137 | + * |
|
| 138 | + * @return string The innermost diagnostic context. |
|
| 139 | + */ |
|
| 140 | + public static function pop() { |
|
| 141 | + if(count(self::$stack) > 0) { |
|
| 142 | + return array_pop(self::$stack); |
|
| 143 | + } else { |
|
| 144 | + return ''; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Looks at the last diagnostic context at the top of this NDC |
|
| 150 | - * without removing it. |
|
| 151 | - * |
|
| 152 | - * <p>The returned value is the value that was pushed last. If no |
|
| 153 | - * context is available, then the empty string "" is returned.</p> |
|
| 154 | - * @return string The innermost diagnostic context. |
|
| 155 | - */ |
|
| 156 | - public static function peek(){ |
|
| 157 | - if(count(self::$stack) > 0) { |
|
| 158 | - return end(self::$stack); |
|
| 159 | - } else { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - } |
|
| 148 | + /** |
|
| 149 | + * Looks at the last diagnostic context at the top of this NDC |
|
| 150 | + * without removing it. |
|
| 151 | + * |
|
| 152 | + * <p>The returned value is the value that was pushed last. If no |
|
| 153 | + * context is available, then the empty string "" is returned.</p> |
|
| 154 | + * @return string The innermost diagnostic context. |
|
| 155 | + */ |
|
| 156 | + public static function peek(){ |
|
| 157 | + if(count(self::$stack) > 0) { |
|
| 158 | + return end(self::$stack); |
|
| 159 | + } else { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Push new diagnostic context information for the current thread. |
|
| 166 | - * |
|
| 167 | - * <p>The contents of the <var>message</var> parameter is |
|
| 168 | - * determined solely by the client. |
|
| 169 | - * |
|
| 170 | - * @param string $message The new diagnostic context information. |
|
| 171 | - */ |
|
| 172 | - public static function push($message) { |
|
| 173 | - array_push(self::$stack, (string)$message); |
|
| 174 | - } |
|
| 164 | + /** |
|
| 165 | + * Push new diagnostic context information for the current thread. |
|
| 166 | + * |
|
| 167 | + * <p>The contents of the <var>message</var> parameter is |
|
| 168 | + * determined solely by the client. |
|
| 169 | + * |
|
| 170 | + * @param string $message The new diagnostic context information. |
|
| 171 | + */ |
|
| 172 | + public static function push($message) { |
|
| 173 | + array_push(self::$stack, (string)$message); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Remove the diagnostic context for this thread. |
|
| 178 | - */ |
|
| 179 | - public static function remove() { |
|
| 180 | - Payone_Log4php_LoggerNDC::clear(); |
|
| 181 | - } |
|
| 176 | + /** |
|
| 177 | + * Remove the diagnostic context for this thread. |
|
| 178 | + */ |
|
| 179 | + public static function remove() { |
|
| 180 | + Payone_Log4php_LoggerNDC::clear(); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Set maximum depth of this diagnostic context. If the current |
|
| 185 | - * depth is smaller or equal to <var>maxDepth</var>, then no |
|
| 186 | - * action is taken. |
|
| 187 | - * |
|
| 188 | - * <p>This method is a convenient alternative to multiple |
|
| 189 | - * {@link pop()} calls. Moreover, it is often the case that at |
|
| 190 | - * the end of complex call sequences, the depth of the NDC is |
|
| 191 | - * unpredictable. The {@link setMaxDepth()} method circumvents |
|
| 192 | - * this problem. |
|
| 193 | - * |
|
| 194 | - * @param integer $maxDepth |
|
| 195 | - * @see getDepth() |
|
| 196 | - */ |
|
| 197 | - public static function setMaxDepth($maxDepth) { |
|
| 198 | - $maxDepth = (int)$maxDepth; |
|
| 199 | - if(Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 200 | - self::$stack = array_slice(self::$stack, 0, $maxDepth); |
|
| 201 | - } |
|
| 202 | - } |
|
| 183 | + /** |
|
| 184 | + * Set maximum depth of this diagnostic context. If the current |
|
| 185 | + * depth is smaller or equal to <var>maxDepth</var>, then no |
|
| 186 | + * action is taken. |
|
| 187 | + * |
|
| 188 | + * <p>This method is a convenient alternative to multiple |
|
| 189 | + * {@link pop()} calls. Moreover, it is often the case that at |
|
| 190 | + * the end of complex call sequences, the depth of the NDC is |
|
| 191 | + * unpredictable. The {@link setMaxDepth()} method circumvents |
|
| 192 | + * this problem. |
|
| 193 | + * |
|
| 194 | + * @param integer $maxDepth |
|
| 195 | + * @see getDepth() |
|
| 196 | + */ |
|
| 197 | + public static function setMaxDepth($maxDepth) { |
|
| 198 | + $maxDepth = (int)$maxDepth; |
|
| 199 | + if(Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 200 | + self::$stack = array_slice(self::$stack, 0, $maxDepth); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -27,15 +27,15 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Payone_Log4php_LoggerRendererException implements Payone_Log4php_LoggerRendererObject { |
| 29 | 29 | |
| 30 | - public function render($o) { |
|
| 31 | - $strRep = 'Throwable('.get_class($o).'): '.$o->getMessage().' in '.$o->getFile().' on line '.$o->getLine(); |
|
| 32 | - $strRep .= PHP_EOL.$o->getTraceAsString(); |
|
| 30 | + public function render($o) { |
|
| 31 | + $strRep = 'Throwable('.get_class($o).'): '.$o->getMessage().' in '.$o->getFile().' on line '.$o->getLine(); |
|
| 32 | + $strRep .= PHP_EOL.$o->getTraceAsString(); |
|
| 33 | 33 | |
| 34 | - if (method_exists($o, 'getPrevious') && $o->getPrevious() !== null) { |
|
| 35 | - $strRep .= PHP_EOL.'Caused by: '.$this->render($o->getPrevious()); |
|
| 36 | - } |
|
| 34 | + if (method_exists($o, 'getPrevious') && $o->getPrevious() !== null) { |
|
| 35 | + $strRep .= PHP_EOL.'Caused by: '.$this->render($o->getPrevious()); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return $strRep; |
|
| 39 | - } |
|
| 38 | + return $strRep; |
|
| 39 | + } |
|
| 40 | 40 | } |
| 41 | 41 | ?> |
| 42 | 42 | \ No newline at end of file |
@@ -27,7 +27,7 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Payone_Log4php_LoggerPatternConverterMethod extends Payone_Log4php_LoggerPatternConverter { |
| 29 | 29 | |
| 30 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 31 | - return $event->getLocationInformation()->getMethodName(); |
|
| 32 | - } |
|
| 30 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 31 | + return $event->getLocationInformation()->getMethodName(); |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -49,246 +49,246 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class Payone_Log4php_LoggerAppenderPDO extends Payone_Log4php_LoggerAppender { |
| 51 | 51 | |
| 52 | - // ****************************************** |
|
| 53 | - // *** Configurable parameters *** |
|
| 54 | - // ****************************************** |
|
| 52 | + // ****************************************** |
|
| 53 | + // *** Configurable parameters *** |
|
| 54 | + // ****************************************** |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * DSN string used to connect to the database. |
|
| 58 | - * @see http://www.php.net/manual/en/pdo.construct.php |
|
| 59 | - */ |
|
| 60 | - protected $dsn; |
|
| 56 | + /** |
|
| 57 | + * DSN string used to connect to the database. |
|
| 58 | + * @see http://www.php.net/manual/en/pdo.construct.php |
|
| 59 | + */ |
|
| 60 | + protected $dsn; |
|
| 61 | 61 | |
| 62 | - /** Database user name. */ |
|
| 63 | - protected $user; |
|
| 62 | + /** Database user name. */ |
|
| 63 | + protected $user; |
|
| 64 | 64 | |
| 65 | - /** Database password. */ |
|
| 66 | - protected $password; |
|
| 65 | + /** Database password. */ |
|
| 66 | + protected $password; |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * The insert query. |
|
| 70 | - * |
|
| 71 | - * The __TABLE__ placeholder will be replaced by the table name from |
|
| 72 | - * {@link $table}. |
|
| 73 | - * |
|
| 74 | - * The questionmarks are part of the prepared statement, and they must |
|
| 75 | - * match the number of conversion specifiers in {@link insertPattern}. |
|
| 76 | - */ |
|
| 77 | - protected $insertSQL = "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?, ?, ?, ?, ?, ?, ?)"; |
|
| 68 | + /** |
|
| 69 | + * The insert query. |
|
| 70 | + * |
|
| 71 | + * The __TABLE__ placeholder will be replaced by the table name from |
|
| 72 | + * {@link $table}. |
|
| 73 | + * |
|
| 74 | + * The questionmarks are part of the prepared statement, and they must |
|
| 75 | + * match the number of conversion specifiers in {@link insertPattern}. |
|
| 76 | + */ |
|
| 77 | + protected $insertSQL = "INSERT INTO __TABLE__ (timestamp, logger, level, message, thread, file, line) VALUES (?, ?, ?, ?, ?, ?, ?)"; |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * A comma separated list of {@link Payone_Log4php_LoggerPatternLayout} format strings |
|
| 81 | - * which replace the "?" in {@link $insertSQL}. |
|
| 82 | - * |
|
| 83 | - * Must contain the same number of comma separated conversion patterns as |
|
| 84 | - * there are question marks in {@link insertSQL}. |
|
| 85 | - * |
|
| 86 | - * @see Payone_Log4php_LoggerPatternLayout For conversion patterns. |
|
| 87 | - */ |
|
| 88 | - protected $insertPattern = "%date{Y-m-d H:i:s},%logger,%level,%message,%pid,%file,%line"; |
|
| 79 | + /** |
|
| 80 | + * A comma separated list of {@link Payone_Log4php_LoggerPatternLayout} format strings |
|
| 81 | + * which replace the "?" in {@link $insertSQL}. |
|
| 82 | + * |
|
| 83 | + * Must contain the same number of comma separated conversion patterns as |
|
| 84 | + * there are question marks in {@link insertSQL}. |
|
| 85 | + * |
|
| 86 | + * @see Payone_Log4php_LoggerPatternLayout For conversion patterns. |
|
| 87 | + */ |
|
| 88 | + protected $insertPattern = "%date{Y-m-d H:i:s},%logger,%level,%message,%pid,%file,%line"; |
|
| 89 | 89 | |
| 90 | - /** Name of the table to which to append log events. */ |
|
| 91 | - protected $table = 'log4php_log'; |
|
| 90 | + /** Name of the table to which to append log events. */ |
|
| 91 | + protected $table = 'log4php_log'; |
|
| 92 | 92 | |
| 93 | - /** The number of recconect attempts to make on failed append. */ |
|
| 94 | - protected $reconnectAttempts = 3; |
|
| 93 | + /** The number of recconect attempts to make on failed append. */ |
|
| 94 | + protected $reconnectAttempts = 3; |
|
| 95 | 95 | |
| 96 | 96 | |
| 97 | - // ****************************************** |
|
| 98 | - // *** Private memebers *** |
|
| 99 | - // ****************************************** |
|
| 97 | + // ****************************************** |
|
| 98 | + // *** Private memebers *** |
|
| 99 | + // ****************************************** |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * The PDO instance. |
|
| 103 | - * @var PDO |
|
| 104 | - */ |
|
| 105 | - protected $db; |
|
| 101 | + /** |
|
| 102 | + * The PDO instance. |
|
| 103 | + * @var PDO |
|
| 104 | + */ |
|
| 105 | + protected $db; |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Prepared statement for the insert query. |
|
| 109 | - * @var PDOStatement |
|
| 110 | - */ |
|
| 111 | - protected $preparedInsert; |
|
| 107 | + /** |
|
| 108 | + * Prepared statement for the insert query. |
|
| 109 | + * @var PDOStatement |
|
| 110 | + */ |
|
| 111 | + protected $preparedInsert; |
|
| 112 | 112 | |
| 113 | - /** This appender does not require a layout. */ |
|
| 114 | - protected $requiresLayout = false; |
|
| 113 | + /** This appender does not require a layout. */ |
|
| 114 | + protected $requiresLayout = false; |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - // ****************************************** |
|
| 118 | - // *** Appender methods *** |
|
| 119 | - // ****************************************** |
|
| 117 | + // ****************************************** |
|
| 118 | + // *** Appender methods *** |
|
| 119 | + // ****************************************** |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Acquires a database connection based on parameters. |
|
| 123 | - * Parses the insert pattern to create a chain of converters which will be |
|
| 124 | - * used in forming query parameters from logging events. |
|
| 125 | - */ |
|
| 126 | - public function activateOptions() { |
|
| 127 | - try { |
|
| 128 | - $this->establishConnection(); |
|
| 129 | - } catch (PDOException $e) { |
|
| 130 | - $this->warn("Failed connecting to database: " . $e->getMessage()); |
|
| 131 | - $this->close(); |
|
| 132 | - return; |
|
| 133 | - } |
|
| 121 | + /** |
|
| 122 | + * Acquires a database connection based on parameters. |
|
| 123 | + * Parses the insert pattern to create a chain of converters which will be |
|
| 124 | + * used in forming query parameters from logging events. |
|
| 125 | + */ |
|
| 126 | + public function activateOptions() { |
|
| 127 | + try { |
|
| 128 | + $this->establishConnection(); |
|
| 129 | + } catch (PDOException $e) { |
|
| 130 | + $this->warn("Failed connecting to database: " . $e->getMessage()); |
|
| 131 | + $this->close(); |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - // Parse the insert patterns; pattern parts are comma delimited |
|
| 136 | - $pieces = explode(',', $this->insertPattern); |
|
| 137 | - $converterMap = Payone_Log4php_LoggerLayoutPattern::getDefaultConverterMap(); |
|
| 138 | - foreach($pieces as $pattern) { |
|
| 139 | - $parser = new Payone_Log4php_LoggerPatternParser($pattern, $converterMap); |
|
| 140 | - $this->converters[] = $parser->parse(); |
|
| 141 | - } |
|
| 135 | + // Parse the insert patterns; pattern parts are comma delimited |
|
| 136 | + $pieces = explode(',', $this->insertPattern); |
|
| 137 | + $converterMap = Payone_Log4php_LoggerLayoutPattern::getDefaultConverterMap(); |
|
| 138 | + foreach($pieces as $pattern) { |
|
| 139 | + $parser = new Payone_Log4php_LoggerPatternParser($pattern, $converterMap); |
|
| 140 | + $this->converters[] = $parser->parse(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $this->closed = false; |
|
| 144 | - } |
|
| 143 | + $this->closed = false; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Connects to the database, and prepares the insert query. |
|
| 148 | - * @throws PDOException If connect or prepare fails. |
|
| 149 | - */ |
|
| 150 | - protected function establishConnection() { |
|
| 151 | - // Acquire database connection |
|
| 152 | - $this->db = new PDO($this->dsn, $this->user, $this->password); |
|
| 153 | - $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 146 | + /** |
|
| 147 | + * Connects to the database, and prepares the insert query. |
|
| 148 | + * @throws PDOException If connect or prepare fails. |
|
| 149 | + */ |
|
| 150 | + protected function establishConnection() { |
|
| 151 | + // Acquire database connection |
|
| 152 | + $this->db = new PDO($this->dsn, $this->user, $this->password); |
|
| 153 | + $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
| 154 | 154 | |
| 155 | - // Prepare the insert statement |
|
| 156 | - $insertSQL = str_replace('__TABLE__', $this->table, $this->insertSQL); |
|
| 157 | - $this->preparedInsert = $this->db->prepare($insertSQL); |
|
| 158 | - } |
|
| 155 | + // Prepare the insert statement |
|
| 156 | + $insertSQL = str_replace('__TABLE__', $this->table, $this->insertSQL); |
|
| 157 | + $this->preparedInsert = $this->db->prepare($insertSQL); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Appends a new event to the database. |
|
| 162 | - * |
|
| 163 | - * If writing to database fails, it will retry by re-establishing the |
|
| 164 | - * connection up to $reconnectAttempts times. If writing still fails, |
|
| 165 | - * the appender will close. |
|
| 166 | - */ |
|
| 167 | - public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 160 | + /** |
|
| 161 | + * Appends a new event to the database. |
|
| 162 | + * |
|
| 163 | + * If writing to database fails, it will retry by re-establishing the |
|
| 164 | + * connection up to $reconnectAttempts times. If writing still fails, |
|
| 165 | + * the appender will close. |
|
| 166 | + */ |
|
| 167 | + public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 168 | 168 | |
| 169 | - for ($attempt = 1; $attempt <= $this->reconnectAttempts; $attempt++) { |
|
| 170 | - try { |
|
| 171 | - // If it's a retry, reestablish the connection |
|
| 172 | - if ($attempt > 1) { |
|
| 173 | - $this->establishConnection(); |
|
| 174 | - } |
|
| 169 | + for ($attempt = 1; $attempt <= $this->reconnectAttempts; $attempt++) { |
|
| 170 | + try { |
|
| 171 | + // If it's a retry, reestablish the connection |
|
| 172 | + if ($attempt > 1) { |
|
| 173 | + $this->establishConnection(); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - // Write to database |
|
| 177 | - @$this->preparedInsert->execute($this->format($event)); |
|
| 178 | - @$this->preparedInsert->closeCursor(); |
|
| 179 | - break; |
|
| 180 | - } catch (PDOException $e) { |
|
| 181 | - $this->warn("Failed writing to database: ". $e->getMessage()); |
|
| 176 | + // Write to database |
|
| 177 | + @$this->preparedInsert->execute($this->format($event)); |
|
| 178 | + @$this->preparedInsert->closeCursor(); |
|
| 179 | + break; |
|
| 180 | + } catch (PDOException $e) { |
|
| 181 | + $this->warn("Failed writing to database: ". $e->getMessage()); |
|
| 182 | 182 | |
| 183 | - // Close the appender if it's the last attempt |
|
| 184 | - if ($attempt == $this->reconnectAttempts) { |
|
| 185 | - $this->warn("Failed after {$this->reconnectAttempts} attempts. Closing appender."); |
|
| 186 | - $this->close(); |
|
| 187 | - } else { |
|
| 188 | - $this->warn("Attempting a reconnect (attempt $attempt of {$this->reconnectAttempts})."); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 183 | + // Close the appender if it's the last attempt |
|
| 184 | + if ($attempt == $this->reconnectAttempts) { |
|
| 185 | + $this->warn("Failed after {$this->reconnectAttempts} attempts. Closing appender."); |
|
| 186 | + $this->close(); |
|
| 187 | + } else { |
|
| 188 | + $this->warn("Attempting a reconnect (attempt $attempt of {$this->reconnectAttempts})."); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Converts the logging event to a series of database parameters by using |
|
| 196 | - * the converter chain which was set up on activation. |
|
| 197 | - */ |
|
| 198 | - protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 199 | - $params = array(); |
|
| 200 | - foreach($this->converters as $converter) { |
|
| 201 | - $buffer = ''; |
|
| 202 | - while ($converter !== null) { |
|
| 203 | - $converter->format($buffer, $event); |
|
| 204 | - $converter = $converter->next; |
|
| 205 | - } |
|
| 206 | - $params[] = $buffer; |
|
| 207 | - } |
|
| 208 | - return $params; |
|
| 209 | - } |
|
| 194 | + /** |
|
| 195 | + * Converts the logging event to a series of database parameters by using |
|
| 196 | + * the converter chain which was set up on activation. |
|
| 197 | + */ |
|
| 198 | + protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 199 | + $params = array(); |
|
| 200 | + foreach($this->converters as $converter) { |
|
| 201 | + $buffer = ''; |
|
| 202 | + while ($converter !== null) { |
|
| 203 | + $converter->format($buffer, $event); |
|
| 204 | + $converter = $converter->next; |
|
| 205 | + } |
|
| 206 | + $params[] = $buffer; |
|
| 207 | + } |
|
| 208 | + return $params; |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - /** |
|
| 212 | - * Closes the connection to the logging database |
|
| 213 | - */ |
|
| 214 | - public function close() { |
|
| 215 | - // Close the connection (if any) |
|
| 216 | - $this->db = null; |
|
| 211 | + /** |
|
| 212 | + * Closes the connection to the logging database |
|
| 213 | + */ |
|
| 214 | + public function close() { |
|
| 215 | + // Close the connection (if any) |
|
| 216 | + $this->db = null; |
|
| 217 | 217 | |
| 218 | - // Close the appender |
|
| 219 | - $this->closed = true; |
|
| 220 | - } |
|
| 218 | + // Close the appender |
|
| 219 | + $this->closed = true; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - // ****************************************** |
|
| 223 | - // *** Accessor methods *** |
|
| 224 | - // ****************************************** |
|
| 222 | + // ****************************************** |
|
| 223 | + // *** Accessor methods *** |
|
| 224 | + // ****************************************** |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Returns the active database handle or null if not established. |
|
| 228 | - * @return PDO |
|
| 229 | - */ |
|
| 230 | - public function getDatabaseHandle() { |
|
| 231 | - return $this->db; |
|
| 232 | - } |
|
| 226 | + /** |
|
| 227 | + * Returns the active database handle or null if not established. |
|
| 228 | + * @return PDO |
|
| 229 | + */ |
|
| 230 | + public function getDatabaseHandle() { |
|
| 231 | + return $this->db; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - /** Sets the username. */ |
|
| 235 | - public function setUser($user) { |
|
| 236 | - $this->setString('user', $user); |
|
| 237 | - } |
|
| 234 | + /** Sets the username. */ |
|
| 235 | + public function setUser($user) { |
|
| 236 | + $this->setString('user', $user); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /** Returns the username. */ |
|
| 240 | - public function getUser($user) { |
|
| 241 | - return $this->user; |
|
| 242 | - } |
|
| 239 | + /** Returns the username. */ |
|
| 240 | + public function getUser($user) { |
|
| 241 | + return $this->user; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - /** Sets the password. */ |
|
| 245 | - public function setPassword($password) { |
|
| 246 | - $this->setString('password', $password); |
|
| 247 | - } |
|
| 244 | + /** Sets the password. */ |
|
| 245 | + public function setPassword($password) { |
|
| 246 | + $this->setString('password', $password); |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** Returns the password. */ |
|
| 250 | - public function getPassword($password) { |
|
| 251 | - return $this->password; |
|
| 252 | - } |
|
| 249 | + /** Returns the password. */ |
|
| 250 | + public function getPassword($password) { |
|
| 251 | + return $this->password; |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - /** Sets the insert SQL. */ |
|
| 255 | - public function setInsertSQL($sql) { |
|
| 256 | - $this->setString('insertSQL', $sql); |
|
| 257 | - } |
|
| 254 | + /** Sets the insert SQL. */ |
|
| 255 | + public function setInsertSQL($sql) { |
|
| 256 | + $this->setString('insertSQL', $sql); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** Returns the insert SQL. */ |
|
| 260 | - public function getInsertSQL($sql) { |
|
| 261 | - return $this->insertSQL; |
|
| 262 | - } |
|
| 259 | + /** Returns the insert SQL. */ |
|
| 260 | + public function getInsertSQL($sql) { |
|
| 261 | + return $this->insertSQL; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - /** Sets the insert pattern. */ |
|
| 265 | - public function setInsertPattern($pattern) { |
|
| 266 | - $this->setString('insertPattern', $pattern); |
|
| 267 | - } |
|
| 264 | + /** Sets the insert pattern. */ |
|
| 265 | + public function setInsertPattern($pattern) { |
|
| 266 | + $this->setString('insertPattern', $pattern); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** Returns the insert pattern. */ |
|
| 270 | - public function getInsertPattern($pattern) { |
|
| 271 | - return $this->insertPattern; |
|
| 272 | - } |
|
| 269 | + /** Returns the insert pattern. */ |
|
| 270 | + public function getInsertPattern($pattern) { |
|
| 271 | + return $this->insertPattern; |
|
| 272 | + } |
|
| 273 | 273 | |
| 274 | - /** Sets the table name. */ |
|
| 275 | - public function setTable($table) { |
|
| 276 | - $this->setString('table', $table); |
|
| 277 | - } |
|
| 274 | + /** Sets the table name. */ |
|
| 275 | + public function setTable($table) { |
|
| 276 | + $this->setString('table', $table); |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - /** Returns the table name. */ |
|
| 280 | - public function getTable($table) { |
|
| 281 | - return $this->table; |
|
| 282 | - } |
|
| 279 | + /** Returns the table name. */ |
|
| 280 | + public function getTable($table) { |
|
| 281 | + return $this->table; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** Sets the DSN string. */ |
|
| 285 | - public function setDSN($dsn) { |
|
| 286 | - $this->setString('dsn', $dsn); |
|
| 287 | - } |
|
| 284 | + /** Sets the DSN string. */ |
|
| 285 | + public function setDSN($dsn) { |
|
| 286 | + $this->setString('dsn', $dsn); |
|
| 287 | + } |
|
| 288 | 288 | |
| 289 | - /** Returns the DSN string. */ |
|
| 290 | - public function getDSN($dsn) { |
|
| 291 | - return $this->setString('dsn', $dsn); |
|
| 292 | - } |
|
| 289 | + /** Returns the DSN string. */ |
|
| 290 | + public function getDSN($dsn) { |
|
| 291 | + return $this->setString('dsn', $dsn); |
|
| 292 | + } |
|
| 293 | 293 | } |
| 294 | 294 | |
@@ -26,13 +26,13 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Payone_Log4php_LoggerPatternConverterLiteral extends Payone_Log4php_LoggerPatternConverter { |
| 28 | 28 | |
| 29 | - private $literalValue; |
|
| 29 | + private $literalValue; |
|
| 30 | 30 | |
| 31 | - public function __construct($literalValue) { |
|
| 32 | - $this->literalValue = $literalValue; |
|
| 33 | - } |
|
| 31 | + public function __construct($literalValue) { |
|
| 32 | + $this->literalValue = $literalValue; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 36 | - return $this->literalValue; |
|
| 37 | - } |
|
| 35 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 36 | + return $this->literalValue; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -26,8 +26,8 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Payone_Log4php_LoggerPatternConverterNDC extends Payone_Log4php_LoggerPatternConverter { |
| 28 | 28 | |
| 29 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | - return $event->getNDC(); |
|
| 31 | - } |
|
| 29 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | + return $event->getNDC(); |
|
| 31 | + } |
|
| 32 | 32 | } |
| 33 | - |
|
| 34 | 33 | \ No newline at end of file |
| 34 | + |
|
| 35 | 35 | \ No newline at end of file |
@@ -32,58 +32,58 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Payone_Log4php_LoggerPatternConverterDate extends Payone_Log4php_LoggerPatternConverter { |
| 34 | 34 | |
| 35 | - const DATE_FORMAT_ISO8601 = 'c'; |
|
| 35 | + const DATE_FORMAT_ISO8601 = 'c'; |
|
| 36 | 36 | |
| 37 | - const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
| 37 | + const DATE_FORMAT_ABSOLUTE = 'H:i:s'; |
|
| 38 | 38 | |
| 39 | - const DATE_FORMAT_DATE = 'd M Y H:i:s.u'; |
|
| 39 | + const DATE_FORMAT_DATE = 'd M Y H:i:s.u'; |
|
| 40 | 40 | |
| 41 | - private $format = self::DATE_FORMAT_ISO8601; |
|
| 41 | + private $format = self::DATE_FORMAT_ISO8601; |
|
| 42 | 42 | |
| 43 | - private $specials = array( |
|
| 44 | - 'ISO8601' => self::DATE_FORMAT_ISO8601, |
|
| 45 | - 'ABSOLUTE' => self::DATE_FORMAT_ABSOLUTE, |
|
| 46 | - 'DATE' => self::DATE_FORMAT_DATE, |
|
| 47 | - ); |
|
| 43 | + private $specials = array( |
|
| 44 | + 'ISO8601' => self::DATE_FORMAT_ISO8601, |
|
| 45 | + 'ABSOLUTE' => self::DATE_FORMAT_ABSOLUTE, |
|
| 46 | + 'DATE' => self::DATE_FORMAT_DATE, |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | - private $useLocalDate = false; |
|
| 49 | + private $useLocalDate = false; |
|
| 50 | 50 | |
| 51 | - public function activateOptions() { |
|
| 51 | + public function activateOptions() { |
|
| 52 | 52 | |
| 53 | - // Parse the option (date format) |
|
| 54 | - if (isset($this->option)) { |
|
| 55 | - if(isset($this->specials[$this->option])) { |
|
| 56 | - $this->format = $this->specials[$this->option]; |
|
| 57 | - } else { |
|
| 58 | - $this->format = $this->option; |
|
| 59 | - } |
|
| 60 | - } |
|
| 53 | + // Parse the option (date format) |
|
| 54 | + if (isset($this->option)) { |
|
| 55 | + if(isset($this->specials[$this->option])) { |
|
| 56 | + $this->format = $this->specials[$this->option]; |
|
| 57 | + } else { |
|
| 58 | + $this->format = $this->option; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - // Check whether the pattern contains milliseconds (u) |
|
| 63 | - if (preg_match('/(?<!\\\\)u/', $this->format)) { |
|
| 64 | - $this->useLocalDate = true; |
|
| 65 | - } |
|
| 66 | - } |
|
| 62 | + // Check whether the pattern contains milliseconds (u) |
|
| 63 | + if (preg_match('/(?<!\\\\)u/', $this->format)) { |
|
| 64 | + $this->useLocalDate = true; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 69 | - if ($this->useLocalDate) { |
|
| 70 | - return $this->date($this->format, $event->getTimeStamp()); |
|
| 71 | - } |
|
| 72 | - return date($this->format, $event->getTimeStamp()); |
|
| 73 | - } |
|
| 68 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 69 | + if ($this->useLocalDate) { |
|
| 70 | + return $this->date($this->format, $event->getTimeStamp()); |
|
| 71 | + } |
|
| 72 | + return date($this->format, $event->getTimeStamp()); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Currently, PHP date() function always returns zeros for milliseconds (u) |
|
| 77 | - * on Windows. This is a replacement function for date() which correctly |
|
| 78 | - * displays milliseconds on all platforms. |
|
| 79 | - * |
|
| 80 | - * It is slower than PHP date() so it should only be used if necessary. |
|
| 81 | - */ |
|
| 82 | - private function date($format, $utimestamp) { |
|
| 83 | - $timestamp = floor($utimestamp); |
|
| 84 | - $ms = floor(($utimestamp - $timestamp) * 1000); |
|
| 85 | - $ms = str_pad($ms, 3, '0', STR_PAD_LEFT); |
|
| 75 | + /** |
|
| 76 | + * Currently, PHP date() function always returns zeros for milliseconds (u) |
|
| 77 | + * on Windows. This is a replacement function for date() which correctly |
|
| 78 | + * displays milliseconds on all platforms. |
|
| 79 | + * |
|
| 80 | + * It is slower than PHP date() so it should only be used if necessary. |
|
| 81 | + */ |
|
| 82 | + private function date($format, $utimestamp) { |
|
| 83 | + $timestamp = floor($utimestamp); |
|
| 84 | + $ms = floor(($utimestamp - $timestamp) * 1000); |
|
| 85 | + $ms = str_pad($ms, 3, '0', STR_PAD_LEFT); |
|
| 86 | 86 | |
| 87 | - return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp); |
|
| 88 | - } |
|
| 87 | + return date(preg_replace('`(?<!\\\\)u`', $ms, $format), $timestamp); |
|
| 88 | + } |
|
| 89 | 89 | } |