@@ -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 | } |
@@ -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(); |
@@ -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 |
@@ -28,11 +28,11 @@ |
||
| 28 | 28 | class Payone_Log4php_LoggerRendererException implements Payone_Log4php_LoggerRendererObject { |
| 29 | 29 | |
| 30 | 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(); |
|
| 31 | + $strRep = 'Throwable(' . get_class($o) . '): ' . $o->getMessage() . ' in ' . $o->getFile() . ' on line ' . $o->getLine(); |
|
| 32 | + $strRep .= PHP_EOL . $o->getTraceAsString(); |
|
| 33 | 33 | |
| 34 | 34 | if (method_exists($o, 'getPrevious') && $o->getPrevious() !== null) { |
| 35 | - $strRep .= PHP_EOL.'Caused by: '.$this->render($o->getPrevious()); |
|
| 35 | + $strRep .= PHP_EOL . 'Caused by: ' . $this->render($o->getPrevious()); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | return $strRep; |
@@ -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 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | // Parse the insert patterns; pattern parts are comma delimited |
| 136 | 136 | $pieces = explode(',', $this->insertPattern); |
| 137 | 137 | $converterMap = Payone_Log4php_LoggerLayoutPattern::getDefaultConverterMap(); |
| 138 | - foreach($pieces as $pattern) { |
|
| 138 | + foreach ($pieces as $pattern) { |
|
| 139 | 139 | $parser = new Payone_Log4php_LoggerPatternParser($pattern, $converterMap); |
| 140 | 140 | $this->converters[] = $parser->parse(); |
| 141 | 141 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | @$this->preparedInsert->closeCursor(); |
| 179 | 179 | break; |
| 180 | 180 | } catch (PDOException $e) { |
| 181 | - $this->warn("Failed writing to database: ". $e->getMessage()); |
|
| 181 | + $this->warn("Failed writing to database: " . $e->getMessage()); |
|
| 182 | 182 | |
| 183 | 183 | // Close the appender if it's the last attempt |
| 184 | 184 | if ($attempt == $this->reconnectAttempts) { |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | */ |
| 198 | 198 | protected function format(Payone_Log4php_LoggerLoggingEvent $event) { |
| 199 | 199 | $params = array(); |
| 200 | - foreach($this->converters as $converter) { |
|
| 200 | + foreach ($this->converters as $converter) { |
|
| 201 | 201 | $buffer = ''; |
| 202 | 202 | while ($converter !== null) { |
| 203 | 203 | $converter->format($buffer, $event); |
@@ -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 |