@@ -36,7 +36,6 @@ |
||
| 36 | 36 | namespace OC; |
| 37 | 37 | |
| 38 | 38 | use InterfaSys\LogNormalizer\Normalizer; |
| 39 | - |
|
| 40 | 39 | use OC\Log\File; |
| 41 | 40 | use OCP\ILogger; |
| 42 | 41 | use OCP\Support\CrashReport\IRegistry; |
@@ -54,340 +54,340 @@ |
||
| 54 | 54 | |
| 55 | 55 | class Log implements ILogger { |
| 56 | 56 | |
| 57 | - /** @var string */ |
|
| 58 | - private $logger; |
|
| 59 | - |
|
| 60 | - /** @var SystemConfig */ |
|
| 61 | - private $config; |
|
| 62 | - |
|
| 63 | - /** @var boolean|null cache the result of the log condition check for the request */ |
|
| 64 | - private $logConditionSatisfied = null; |
|
| 65 | - |
|
| 66 | - /** @var Normalizer */ |
|
| 67 | - private $normalizer; |
|
| 68 | - |
|
| 69 | - /** @var IRegistry */ |
|
| 70 | - private $crashReporters; |
|
| 71 | - |
|
| 72 | - protected $methodsWithSensitiveParameters = [ |
|
| 73 | - // Session/User |
|
| 74 | - 'completeLogin', |
|
| 75 | - 'login', |
|
| 76 | - 'checkPassword', |
|
| 77 | - 'checkPasswordNoLogging', |
|
| 78 | - 'loginWithPassword', |
|
| 79 | - 'updatePrivateKeyPassword', |
|
| 80 | - 'validateUserPass', |
|
| 81 | - 'loginWithToken', |
|
| 82 | - '\{closure\}', |
|
| 83 | - |
|
| 84 | - // TokenProvider |
|
| 85 | - 'getToken', |
|
| 86 | - 'isTokenPassword', |
|
| 87 | - 'getPassword', |
|
| 88 | - 'decryptPassword', |
|
| 89 | - 'logClientIn', |
|
| 90 | - 'generateToken', |
|
| 91 | - 'validateToken', |
|
| 92 | - |
|
| 93 | - // TwoFactorAuth |
|
| 94 | - 'solveChallenge', |
|
| 95 | - 'verifyChallenge', |
|
| 96 | - |
|
| 97 | - // ICrypto |
|
| 98 | - 'calculateHMAC', |
|
| 99 | - 'encrypt', |
|
| 100 | - 'decrypt', |
|
| 101 | - |
|
| 102 | - // LoginController |
|
| 103 | - 'tryLogin', |
|
| 104 | - 'confirmPassword', |
|
| 105 | - |
|
| 106 | - // LDAP |
|
| 107 | - 'bind', |
|
| 108 | - 'areCredentialsValid', |
|
| 109 | - 'invokeLDAPMethod', |
|
| 110 | - |
|
| 111 | - // Encryption |
|
| 112 | - 'storeKeyPair', |
|
| 113 | - 'setupUser', |
|
| 114 | - ]; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param string $logger The logger that should be used |
|
| 118 | - * @param SystemConfig $config the system config object |
|
| 119 | - * @param Normalizer|null $normalizer |
|
| 120 | - * @param IRegistry|null $registry |
|
| 121 | - */ |
|
| 122 | - public function __construct($logger = null, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) { |
|
| 123 | - // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
|
| 124 | - if($config === null) { |
|
| 125 | - $config = \OC::$server->getSystemConfig(); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $this->config = $config; |
|
| 129 | - |
|
| 130 | - // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
|
| 131 | - if($logger === null) { |
|
| 132 | - $logType = $this->config->getValue('log_type', 'file'); |
|
| 133 | - $this->logger = static::getLogClass($logType); |
|
| 134 | - call_user_func([$this->logger, 'init']); |
|
| 135 | - } else { |
|
| 136 | - $this->logger = $logger; |
|
| 137 | - } |
|
| 138 | - if ($normalizer === null) { |
|
| 139 | - $this->normalizer = new Normalizer(); |
|
| 140 | - } else { |
|
| 141 | - $this->normalizer = $normalizer; |
|
| 142 | - } |
|
| 143 | - $this->crashReporters = $registry; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * System is unusable. |
|
| 148 | - * |
|
| 149 | - * @param string $message |
|
| 150 | - * @param array $context |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - public function emergency(string $message, array $context = []) { |
|
| 154 | - $this->log(Util::FATAL, $message, $context); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Action must be taken immediately. |
|
| 159 | - * |
|
| 160 | - * Example: Entire website down, database unavailable, etc. This should |
|
| 161 | - * trigger the SMS alerts and wake you up. |
|
| 162 | - * |
|
| 163 | - * @param string $message |
|
| 164 | - * @param array $context |
|
| 165 | - * @return void |
|
| 166 | - */ |
|
| 167 | - public function alert(string $message, array $context = []) { |
|
| 168 | - $this->log(Util::ERROR, $message, $context); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Critical conditions. |
|
| 173 | - * |
|
| 174 | - * Example: Application component unavailable, unexpected exception. |
|
| 175 | - * |
|
| 176 | - * @param string $message |
|
| 177 | - * @param array $context |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function critical(string $message, array $context = []) { |
|
| 181 | - $this->log(Util::ERROR, $message, $context); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * Runtime errors that do not require immediate action but should typically |
|
| 186 | - * be logged and monitored. |
|
| 187 | - * |
|
| 188 | - * @param string $message |
|
| 189 | - * @param array $context |
|
| 190 | - * @return void |
|
| 191 | - */ |
|
| 192 | - public function error(string $message, array $context = []) { |
|
| 193 | - $this->log(Util::ERROR, $message, $context); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Exceptional occurrences that are not errors. |
|
| 198 | - * |
|
| 199 | - * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
| 200 | - * that are not necessarily wrong. |
|
| 201 | - * |
|
| 202 | - * @param string $message |
|
| 203 | - * @param array $context |
|
| 204 | - * @return void |
|
| 205 | - */ |
|
| 206 | - public function warning(string $message, array $context = []) { |
|
| 207 | - $this->log(Util::WARN, $message, $context); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Normal but significant events. |
|
| 212 | - * |
|
| 213 | - * @param string $message |
|
| 214 | - * @param array $context |
|
| 215 | - * @return void |
|
| 216 | - */ |
|
| 217 | - public function notice(string $message, array $context = []) { |
|
| 218 | - $this->log(Util::INFO, $message, $context); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Interesting events. |
|
| 223 | - * |
|
| 224 | - * Example: User logs in, SQL logs. |
|
| 225 | - * |
|
| 226 | - * @param string $message |
|
| 227 | - * @param array $context |
|
| 228 | - * @return void |
|
| 229 | - */ |
|
| 230 | - public function info(string $message, array $context = []) { |
|
| 231 | - $this->log(Util::INFO, $message, $context); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Detailed debug information. |
|
| 236 | - * |
|
| 237 | - * @param string $message |
|
| 238 | - * @param array $context |
|
| 239 | - * @return void |
|
| 240 | - */ |
|
| 241 | - public function debug(string $message, array $context = []) { |
|
| 242 | - $this->log(Util::DEBUG, $message, $context); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Logs with an arbitrary level. |
|
| 248 | - * |
|
| 249 | - * @param int $level |
|
| 250 | - * @param string $message |
|
| 251 | - * @param array $context |
|
| 252 | - * @return void |
|
| 253 | - */ |
|
| 254 | - public function log(int $level, string $message, array $context = []) { |
|
| 255 | - $minLevel = $this->getLogLevel($context); |
|
| 256 | - |
|
| 257 | - array_walk($context, [$this->normalizer, 'format']); |
|
| 258 | - |
|
| 259 | - $app = $context['app'] ?: 'no app in context'; |
|
| 260 | - |
|
| 261 | - // interpolate $message as defined in PSR-3 |
|
| 262 | - $replace = []; |
|
| 263 | - foreach ($context as $key => $val) { |
|
| 264 | - $replace['{' . $key . '}'] = $val; |
|
| 265 | - } |
|
| 266 | - $message = strtr($message, $replace); |
|
| 267 | - |
|
| 268 | - if ($level >= $minLevel) { |
|
| 269 | - call_user_func([$this->logger, 'write'], $app, $message, $level); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - private function getLogLevel($context) { |
|
| 274 | - /** |
|
| 275 | - * check for a special log condition - this enables an increased log on |
|
| 276 | - * a per request/user base |
|
| 277 | - */ |
|
| 278 | - if($this->logConditionSatisfied === null) { |
|
| 279 | - // default to false to just process this once per request |
|
| 280 | - $this->logConditionSatisfied = false; |
|
| 281 | - if(!empty($logCondition)) { |
|
| 282 | - |
|
| 283 | - // check for secret token in the request |
|
| 284 | - if(isset($logCondition['shared_secret'])) { |
|
| 285 | - $request = \OC::$server->getRequest(); |
|
| 286 | - |
|
| 287 | - // if token is found in the request change set the log condition to satisfied |
|
| 288 | - if($request && hash_equals($logCondition['shared_secret'], $request->getParam('log_secret', ''))) { |
|
| 289 | - $this->logConditionSatisfied = true; |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // check for user |
|
| 294 | - if(isset($logCondition['users'])) { |
|
| 295 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 296 | - |
|
| 297 | - // if the user matches set the log condition to satisfied |
|
| 298 | - if($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { |
|
| 299 | - $this->logConditionSatisfied = true; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // if log condition is satisfied change the required log level to DEBUG |
|
| 306 | - if($this->logConditionSatisfied) { |
|
| 307 | - return Util::DEBUG; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - if (isset($context['app'])) { |
|
| 311 | - $logCondition = $this->config->getValue('log.condition', []); |
|
| 312 | - $app = $context['app']; |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * check log condition based on the context of each log message |
|
| 316 | - * once this is met -> change the required log level to debug |
|
| 317 | - */ |
|
| 318 | - if (!empty($logCondition) |
|
| 319 | - && isset($logCondition['apps']) |
|
| 320 | - && in_array($app, $logCondition['apps'], true)) { |
|
| 321 | - return Util::DEBUG; |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return min($this->config->getValue('loglevel', Util::WARN), Util::FATAL); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * Logs an exception very detailed |
|
| 330 | - * |
|
| 331 | - * @param \Exception|\Throwable $exception |
|
| 332 | - * @param array $context |
|
| 333 | - * @return void |
|
| 334 | - * @since 8.2.0 |
|
| 335 | - */ |
|
| 336 | - public function logException(\Throwable $exception, array $context = []) { |
|
| 337 | - $app = $context['app'] ?: 'no app in context'; |
|
| 338 | - $level = $context['level'] ?: Util::ERROR; |
|
| 339 | - |
|
| 340 | - $data = [ |
|
| 341 | - 'CustomMessage' => isset($context['message']) ? $context['message'] : '--', |
|
| 342 | - 'Exception' => get_class($exception), |
|
| 343 | - 'Message' => $exception->getMessage(), |
|
| 344 | - 'Code' => $exception->getCode(), |
|
| 345 | - 'Trace' => $exception->getTrace(), |
|
| 346 | - 'File' => $exception->getFile(), |
|
| 347 | - 'Line' => $exception->getLine(), |
|
| 348 | - ]; |
|
| 349 | - if ($exception instanceof HintException) { |
|
| 350 | - $data['Hint'] = $exception->getHint(); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - $minLevel = $this->getLogLevel($context); |
|
| 354 | - |
|
| 355 | - array_walk($context, [$this->normalizer, 'format']); |
|
| 356 | - |
|
| 357 | - if ($level >= $minLevel) { |
|
| 358 | - if ($this->logger === File::class) { |
|
| 359 | - call_user_func([$this->logger, 'write'], $app, $data, $level); |
|
| 360 | - } else { |
|
| 361 | - $entry = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR); |
|
| 362 | - call_user_func([$this->logger, 'write'], $app, $entry, $level); |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - $context['level'] = $level; |
|
| 367 | - if (!is_null($this->crashReporters)) { |
|
| 368 | - $this->crashReporters->delegateReport($exception, $context); |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @param string $logType |
|
| 374 | - * @return string |
|
| 375 | - * @internal |
|
| 376 | - */ |
|
| 377 | - public static function getLogClass(string $logType): string { |
|
| 378 | - switch (strtolower($logType)) { |
|
| 379 | - case 'errorlog': |
|
| 380 | - return \OC\Log\Errorlog::class; |
|
| 381 | - case 'syslog': |
|
| 382 | - return \OC\Log\Syslog::class; |
|
| 383 | - case 'file': |
|
| 384 | - return \OC\Log\File::class; |
|
| 385 | - |
|
| 386 | - // Backwards compatibility for old and fallback for unknown log types |
|
| 387 | - case 'owncloud': |
|
| 388 | - case 'nextcloud': |
|
| 389 | - default: |
|
| 390 | - return \OC\Log\File::class; |
|
| 391 | - } |
|
| 392 | - } |
|
| 57 | + /** @var string */ |
|
| 58 | + private $logger; |
|
| 59 | + |
|
| 60 | + /** @var SystemConfig */ |
|
| 61 | + private $config; |
|
| 62 | + |
|
| 63 | + /** @var boolean|null cache the result of the log condition check for the request */ |
|
| 64 | + private $logConditionSatisfied = null; |
|
| 65 | + |
|
| 66 | + /** @var Normalizer */ |
|
| 67 | + private $normalizer; |
|
| 68 | + |
|
| 69 | + /** @var IRegistry */ |
|
| 70 | + private $crashReporters; |
|
| 71 | + |
|
| 72 | + protected $methodsWithSensitiveParameters = [ |
|
| 73 | + // Session/User |
|
| 74 | + 'completeLogin', |
|
| 75 | + 'login', |
|
| 76 | + 'checkPassword', |
|
| 77 | + 'checkPasswordNoLogging', |
|
| 78 | + 'loginWithPassword', |
|
| 79 | + 'updatePrivateKeyPassword', |
|
| 80 | + 'validateUserPass', |
|
| 81 | + 'loginWithToken', |
|
| 82 | + '\{closure\}', |
|
| 83 | + |
|
| 84 | + // TokenProvider |
|
| 85 | + 'getToken', |
|
| 86 | + 'isTokenPassword', |
|
| 87 | + 'getPassword', |
|
| 88 | + 'decryptPassword', |
|
| 89 | + 'logClientIn', |
|
| 90 | + 'generateToken', |
|
| 91 | + 'validateToken', |
|
| 92 | + |
|
| 93 | + // TwoFactorAuth |
|
| 94 | + 'solveChallenge', |
|
| 95 | + 'verifyChallenge', |
|
| 96 | + |
|
| 97 | + // ICrypto |
|
| 98 | + 'calculateHMAC', |
|
| 99 | + 'encrypt', |
|
| 100 | + 'decrypt', |
|
| 101 | + |
|
| 102 | + // LoginController |
|
| 103 | + 'tryLogin', |
|
| 104 | + 'confirmPassword', |
|
| 105 | + |
|
| 106 | + // LDAP |
|
| 107 | + 'bind', |
|
| 108 | + 'areCredentialsValid', |
|
| 109 | + 'invokeLDAPMethod', |
|
| 110 | + |
|
| 111 | + // Encryption |
|
| 112 | + 'storeKeyPair', |
|
| 113 | + 'setupUser', |
|
| 114 | + ]; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param string $logger The logger that should be used |
|
| 118 | + * @param SystemConfig $config the system config object |
|
| 119 | + * @param Normalizer|null $normalizer |
|
| 120 | + * @param IRegistry|null $registry |
|
| 121 | + */ |
|
| 122 | + public function __construct($logger = null, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) { |
|
| 123 | + // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
|
| 124 | + if($config === null) { |
|
| 125 | + $config = \OC::$server->getSystemConfig(); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $this->config = $config; |
|
| 129 | + |
|
| 130 | + // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
|
| 131 | + if($logger === null) { |
|
| 132 | + $logType = $this->config->getValue('log_type', 'file'); |
|
| 133 | + $this->logger = static::getLogClass($logType); |
|
| 134 | + call_user_func([$this->logger, 'init']); |
|
| 135 | + } else { |
|
| 136 | + $this->logger = $logger; |
|
| 137 | + } |
|
| 138 | + if ($normalizer === null) { |
|
| 139 | + $this->normalizer = new Normalizer(); |
|
| 140 | + } else { |
|
| 141 | + $this->normalizer = $normalizer; |
|
| 142 | + } |
|
| 143 | + $this->crashReporters = $registry; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * System is unusable. |
|
| 148 | + * |
|
| 149 | + * @param string $message |
|
| 150 | + * @param array $context |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + public function emergency(string $message, array $context = []) { |
|
| 154 | + $this->log(Util::FATAL, $message, $context); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Action must be taken immediately. |
|
| 159 | + * |
|
| 160 | + * Example: Entire website down, database unavailable, etc. This should |
|
| 161 | + * trigger the SMS alerts and wake you up. |
|
| 162 | + * |
|
| 163 | + * @param string $message |
|
| 164 | + * @param array $context |
|
| 165 | + * @return void |
|
| 166 | + */ |
|
| 167 | + public function alert(string $message, array $context = []) { |
|
| 168 | + $this->log(Util::ERROR, $message, $context); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Critical conditions. |
|
| 173 | + * |
|
| 174 | + * Example: Application component unavailable, unexpected exception. |
|
| 175 | + * |
|
| 176 | + * @param string $message |
|
| 177 | + * @param array $context |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function critical(string $message, array $context = []) { |
|
| 181 | + $this->log(Util::ERROR, $message, $context); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * Runtime errors that do not require immediate action but should typically |
|
| 186 | + * be logged and monitored. |
|
| 187 | + * |
|
| 188 | + * @param string $message |
|
| 189 | + * @param array $context |
|
| 190 | + * @return void |
|
| 191 | + */ |
|
| 192 | + public function error(string $message, array $context = []) { |
|
| 193 | + $this->log(Util::ERROR, $message, $context); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Exceptional occurrences that are not errors. |
|
| 198 | + * |
|
| 199 | + * Example: Use of deprecated APIs, poor use of an API, undesirable things |
|
| 200 | + * that are not necessarily wrong. |
|
| 201 | + * |
|
| 202 | + * @param string $message |
|
| 203 | + * @param array $context |
|
| 204 | + * @return void |
|
| 205 | + */ |
|
| 206 | + public function warning(string $message, array $context = []) { |
|
| 207 | + $this->log(Util::WARN, $message, $context); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Normal but significant events. |
|
| 212 | + * |
|
| 213 | + * @param string $message |
|
| 214 | + * @param array $context |
|
| 215 | + * @return void |
|
| 216 | + */ |
|
| 217 | + public function notice(string $message, array $context = []) { |
|
| 218 | + $this->log(Util::INFO, $message, $context); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Interesting events. |
|
| 223 | + * |
|
| 224 | + * Example: User logs in, SQL logs. |
|
| 225 | + * |
|
| 226 | + * @param string $message |
|
| 227 | + * @param array $context |
|
| 228 | + * @return void |
|
| 229 | + */ |
|
| 230 | + public function info(string $message, array $context = []) { |
|
| 231 | + $this->log(Util::INFO, $message, $context); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Detailed debug information. |
|
| 236 | + * |
|
| 237 | + * @param string $message |
|
| 238 | + * @param array $context |
|
| 239 | + * @return void |
|
| 240 | + */ |
|
| 241 | + public function debug(string $message, array $context = []) { |
|
| 242 | + $this->log(Util::DEBUG, $message, $context); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Logs with an arbitrary level. |
|
| 248 | + * |
|
| 249 | + * @param int $level |
|
| 250 | + * @param string $message |
|
| 251 | + * @param array $context |
|
| 252 | + * @return void |
|
| 253 | + */ |
|
| 254 | + public function log(int $level, string $message, array $context = []) { |
|
| 255 | + $minLevel = $this->getLogLevel($context); |
|
| 256 | + |
|
| 257 | + array_walk($context, [$this->normalizer, 'format']); |
|
| 258 | + |
|
| 259 | + $app = $context['app'] ?: 'no app in context'; |
|
| 260 | + |
|
| 261 | + // interpolate $message as defined in PSR-3 |
|
| 262 | + $replace = []; |
|
| 263 | + foreach ($context as $key => $val) { |
|
| 264 | + $replace['{' . $key . '}'] = $val; |
|
| 265 | + } |
|
| 266 | + $message = strtr($message, $replace); |
|
| 267 | + |
|
| 268 | + if ($level >= $minLevel) { |
|
| 269 | + call_user_func([$this->logger, 'write'], $app, $message, $level); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + private function getLogLevel($context) { |
|
| 274 | + /** |
|
| 275 | + * check for a special log condition - this enables an increased log on |
|
| 276 | + * a per request/user base |
|
| 277 | + */ |
|
| 278 | + if($this->logConditionSatisfied === null) { |
|
| 279 | + // default to false to just process this once per request |
|
| 280 | + $this->logConditionSatisfied = false; |
|
| 281 | + if(!empty($logCondition)) { |
|
| 282 | + |
|
| 283 | + // check for secret token in the request |
|
| 284 | + if(isset($logCondition['shared_secret'])) { |
|
| 285 | + $request = \OC::$server->getRequest(); |
|
| 286 | + |
|
| 287 | + // if token is found in the request change set the log condition to satisfied |
|
| 288 | + if($request && hash_equals($logCondition['shared_secret'], $request->getParam('log_secret', ''))) { |
|
| 289 | + $this->logConditionSatisfied = true; |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // check for user |
|
| 294 | + if(isset($logCondition['users'])) { |
|
| 295 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 296 | + |
|
| 297 | + // if the user matches set the log condition to satisfied |
|
| 298 | + if($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { |
|
| 299 | + $this->logConditionSatisfied = true; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // if log condition is satisfied change the required log level to DEBUG |
|
| 306 | + if($this->logConditionSatisfied) { |
|
| 307 | + return Util::DEBUG; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + if (isset($context['app'])) { |
|
| 311 | + $logCondition = $this->config->getValue('log.condition', []); |
|
| 312 | + $app = $context['app']; |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * check log condition based on the context of each log message |
|
| 316 | + * once this is met -> change the required log level to debug |
|
| 317 | + */ |
|
| 318 | + if (!empty($logCondition) |
|
| 319 | + && isset($logCondition['apps']) |
|
| 320 | + && in_array($app, $logCondition['apps'], true)) { |
|
| 321 | + return Util::DEBUG; |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return min($this->config->getValue('loglevel', Util::WARN), Util::FATAL); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * Logs an exception very detailed |
|
| 330 | + * |
|
| 331 | + * @param \Exception|\Throwable $exception |
|
| 332 | + * @param array $context |
|
| 333 | + * @return void |
|
| 334 | + * @since 8.2.0 |
|
| 335 | + */ |
|
| 336 | + public function logException(\Throwable $exception, array $context = []) { |
|
| 337 | + $app = $context['app'] ?: 'no app in context'; |
|
| 338 | + $level = $context['level'] ?: Util::ERROR; |
|
| 339 | + |
|
| 340 | + $data = [ |
|
| 341 | + 'CustomMessage' => isset($context['message']) ? $context['message'] : '--', |
|
| 342 | + 'Exception' => get_class($exception), |
|
| 343 | + 'Message' => $exception->getMessage(), |
|
| 344 | + 'Code' => $exception->getCode(), |
|
| 345 | + 'Trace' => $exception->getTrace(), |
|
| 346 | + 'File' => $exception->getFile(), |
|
| 347 | + 'Line' => $exception->getLine(), |
|
| 348 | + ]; |
|
| 349 | + if ($exception instanceof HintException) { |
|
| 350 | + $data['Hint'] = $exception->getHint(); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + $minLevel = $this->getLogLevel($context); |
|
| 354 | + |
|
| 355 | + array_walk($context, [$this->normalizer, 'format']); |
|
| 356 | + |
|
| 357 | + if ($level >= $minLevel) { |
|
| 358 | + if ($this->logger === File::class) { |
|
| 359 | + call_user_func([$this->logger, 'write'], $app, $data, $level); |
|
| 360 | + } else { |
|
| 361 | + $entry = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR); |
|
| 362 | + call_user_func([$this->logger, 'write'], $app, $entry, $level); |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + $context['level'] = $level; |
|
| 367 | + if (!is_null($this->crashReporters)) { |
|
| 368 | + $this->crashReporters->delegateReport($exception, $context); |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @param string $logType |
|
| 374 | + * @return string |
|
| 375 | + * @internal |
|
| 376 | + */ |
|
| 377 | + public static function getLogClass(string $logType): string { |
|
| 378 | + switch (strtolower($logType)) { |
|
| 379 | + case 'errorlog': |
|
| 380 | + return \OC\Log\Errorlog::class; |
|
| 381 | + case 'syslog': |
|
| 382 | + return \OC\Log\Syslog::class; |
|
| 383 | + case 'file': |
|
| 384 | + return \OC\Log\File::class; |
|
| 385 | + |
|
| 386 | + // Backwards compatibility for old and fallback for unknown log types |
|
| 387 | + case 'owncloud': |
|
| 388 | + case 'nextcloud': |
|
| 389 | + default: |
|
| 390 | + return \OC\Log\File::class; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | 393 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -declare(strict_types=1); |
|
| 2 | +declare(strict_types = 1); |
|
| 3 | 3 | /** |
| 4 | 4 | * @copyright Copyright (c) 2016, ownCloud, Inc. |
| 5 | 5 | * |
@@ -121,14 +121,14 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function __construct($logger = null, SystemConfig $config = null, $normalizer = null, IRegistry $registry = null) { |
| 123 | 123 | // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
| 124 | - if($config === null) { |
|
| 124 | + if ($config === null) { |
|
| 125 | 125 | $config = \OC::$server->getSystemConfig(); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $this->config = $config; |
| 129 | 129 | |
| 130 | 130 | // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
| 131 | - if($logger === null) { |
|
| 131 | + if ($logger === null) { |
|
| 132 | 132 | $logType = $this->config->getValue('log_type', 'file'); |
| 133 | 133 | $this->logger = static::getLogClass($logType); |
| 134 | 134 | call_user_func([$this->logger, 'init']); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | // interpolate $message as defined in PSR-3 |
| 262 | 262 | $replace = []; |
| 263 | 263 | foreach ($context as $key => $val) { |
| 264 | - $replace['{' . $key . '}'] = $val; |
|
| 264 | + $replace['{'.$key.'}'] = $val; |
|
| 265 | 265 | } |
| 266 | 266 | $message = strtr($message, $replace); |
| 267 | 267 | |
@@ -275,27 +275,27 @@ discard block |
||
| 275 | 275 | * check for a special log condition - this enables an increased log on |
| 276 | 276 | * a per request/user base |
| 277 | 277 | */ |
| 278 | - if($this->logConditionSatisfied === null) { |
|
| 278 | + if ($this->logConditionSatisfied === null) { |
|
| 279 | 279 | // default to false to just process this once per request |
| 280 | 280 | $this->logConditionSatisfied = false; |
| 281 | - if(!empty($logCondition)) { |
|
| 281 | + if (!empty($logCondition)) { |
|
| 282 | 282 | |
| 283 | 283 | // check for secret token in the request |
| 284 | - if(isset($logCondition['shared_secret'])) { |
|
| 284 | + if (isset($logCondition['shared_secret'])) { |
|
| 285 | 285 | $request = \OC::$server->getRequest(); |
| 286 | 286 | |
| 287 | 287 | // if token is found in the request change set the log condition to satisfied |
| 288 | - if($request && hash_equals($logCondition['shared_secret'], $request->getParam('log_secret', ''))) { |
|
| 288 | + if ($request && hash_equals($logCondition['shared_secret'], $request->getParam('log_secret', ''))) { |
|
| 289 | 289 | $this->logConditionSatisfied = true; |
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | // check for user |
| 294 | - if(isset($logCondition['users'])) { |
|
| 294 | + if (isset($logCondition['users'])) { |
|
| 295 | 295 | $user = \OC::$server->getUserSession()->getUser(); |
| 296 | 296 | |
| 297 | 297 | // if the user matches set the log condition to satisfied |
| 298 | - if($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { |
|
| 298 | + if ($user !== null && in_array($user->getUID(), $logCondition['users'], true)) { |
|
| 299 | 299 | $this->logConditionSatisfied = true; |
| 300 | 300 | } |
| 301 | 301 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // if log condition is satisfied change the required log level to DEBUG |
| 306 | - if($this->logConditionSatisfied) { |
|
| 306 | + if ($this->logConditionSatisfied) { |
|
| 307 | 307 | return Util::DEBUG; |
| 308 | 308 | } |
| 309 | 309 | |
@@ -44,166 +44,166 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | |
| 46 | 46 | class File { |
| 47 | - static protected $logFile; |
|
| 47 | + static protected $logFile; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Init class data |
|
| 51 | - */ |
|
| 52 | - public static function init() { |
|
| 53 | - $systemConfig = \OC::$server->getSystemConfig(); |
|
| 54 | - $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log'; |
|
| 55 | - self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile); |
|
| 49 | + /** |
|
| 50 | + * Init class data |
|
| 51 | + */ |
|
| 52 | + public static function init() { |
|
| 53 | + $systemConfig = \OC::$server->getSystemConfig(); |
|
| 54 | + $defaultLogFile = $systemConfig->getValue("datadirectory", \OC::$SERVERROOT.'/data').'/nextcloud.log'; |
|
| 55 | + self::$logFile = $systemConfig->getValue("logfile", $defaultLogFile); |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Fall back to default log file if specified logfile does not exist |
|
| 59 | - * and can not be created. |
|
| 60 | - */ |
|
| 61 | - if (!file_exists(self::$logFile)) { |
|
| 62 | - if(!is_writable(dirname(self::$logFile))) { |
|
| 63 | - self::$logFile = $defaultLogFile; |
|
| 64 | - } else { |
|
| 65 | - if(!touch(self::$logFile)) { |
|
| 66 | - self::$logFile = $defaultLogFile; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 57 | + /** |
|
| 58 | + * Fall back to default log file if specified logfile does not exist |
|
| 59 | + * and can not be created. |
|
| 60 | + */ |
|
| 61 | + if (!file_exists(self::$logFile)) { |
|
| 62 | + if(!is_writable(dirname(self::$logFile))) { |
|
| 63 | + self::$logFile = $defaultLogFile; |
|
| 64 | + } else { |
|
| 65 | + if(!touch(self::$logFile)) { |
|
| 66 | + self::$logFile = $defaultLogFile; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * write a message in the log |
|
| 74 | - * @param string $app |
|
| 75 | - * @param string|array $message |
|
| 76 | - * @param int $level |
|
| 77 | - */ |
|
| 78 | - public static function write($app, $message, $level) { |
|
| 79 | - $config = \OC::$server->getSystemConfig(); |
|
| 72 | + /** |
|
| 73 | + * write a message in the log |
|
| 74 | + * @param string $app |
|
| 75 | + * @param string|array $message |
|
| 76 | + * @param int $level |
|
| 77 | + */ |
|
| 78 | + public static function write($app, $message, $level) { |
|
| 79 | + $config = \OC::$server->getSystemConfig(); |
|
| 80 | 80 | |
| 81 | - // default to ISO8601 |
|
| 82 | - $format = $config->getValue('logdateformat', \DateTime::ATOM); |
|
| 83 | - $logTimeZone = $config->getValue('logtimezone', 'UTC'); |
|
| 84 | - try { |
|
| 85 | - $timezone = new \DateTimeZone($logTimeZone); |
|
| 86 | - } catch (\Exception $e) { |
|
| 87 | - $timezone = new \DateTimeZone('UTC'); |
|
| 88 | - } |
|
| 89 | - $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); |
|
| 90 | - if ($time === false) { |
|
| 91 | - $time = new \DateTime(null, $timezone); |
|
| 92 | - } else { |
|
| 93 | - // apply timezone if $time is created from UNIX timestamp |
|
| 94 | - $time->setTimezone($timezone); |
|
| 95 | - } |
|
| 96 | - $request = \OC::$server->getRequest(); |
|
| 97 | - $reqId = $request->getId(); |
|
| 98 | - $remoteAddr = $request->getRemoteAddress(); |
|
| 99 | - // remove username/passwords from URLs before writing the to the log file |
|
| 100 | - $time = $time->format($format); |
|
| 101 | - $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; |
|
| 102 | - $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; |
|
| 103 | - if($config->getValue('installed', false)) { |
|
| 104 | - $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; |
|
| 105 | - } else { |
|
| 106 | - $user = '--'; |
|
| 107 | - } |
|
| 108 | - $userAgent = $request->getHeader('User-Agent'); |
|
| 109 | - if ($userAgent === '') { |
|
| 110 | - $userAgent = '--'; |
|
| 111 | - } |
|
| 112 | - $version = $config->getValue('version', ''); |
|
| 113 | - $entry = compact( |
|
| 114 | - 'reqId', |
|
| 115 | - 'level', |
|
| 116 | - 'time', |
|
| 117 | - 'remoteAddr', |
|
| 118 | - 'user', |
|
| 119 | - 'app', |
|
| 120 | - 'method', |
|
| 121 | - 'url', |
|
| 122 | - 'message', |
|
| 123 | - 'userAgent', |
|
| 124 | - 'version' |
|
| 125 | - ); |
|
| 126 | - // PHP's json_encode only accept proper UTF-8 strings, loop over all |
|
| 127 | - // elements to ensure that they are properly UTF-8 compliant or convert |
|
| 128 | - // them manually. |
|
| 129 | - foreach($entry as $key => $value) { |
|
| 130 | - if(is_string($value)) { |
|
| 131 | - $testEncode = json_encode($value); |
|
| 132 | - if($testEncode === false) { |
|
| 133 | - $entry[$key] = utf8_encode($value); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR); |
|
| 138 | - $handle = @fopen(self::$logFile, 'a'); |
|
| 139 | - if ((fileperms(self::$logFile) & 0777) != 0640) { |
|
| 140 | - @chmod(self::$logFile, 0640); |
|
| 141 | - } |
|
| 142 | - if ($handle) { |
|
| 143 | - fwrite($handle, $entry."\n"); |
|
| 144 | - fclose($handle); |
|
| 145 | - } else { |
|
| 146 | - // Fall back to error_log |
|
| 147 | - error_log($entry); |
|
| 148 | - } |
|
| 149 | - if (php_sapi_name() === 'cli-server') { |
|
| 150 | - error_log($message, 4); |
|
| 151 | - } |
|
| 152 | - } |
|
| 81 | + // default to ISO8601 |
|
| 82 | + $format = $config->getValue('logdateformat', \DateTime::ATOM); |
|
| 83 | + $logTimeZone = $config->getValue('logtimezone', 'UTC'); |
|
| 84 | + try { |
|
| 85 | + $timezone = new \DateTimeZone($logTimeZone); |
|
| 86 | + } catch (\Exception $e) { |
|
| 87 | + $timezone = new \DateTimeZone('UTC'); |
|
| 88 | + } |
|
| 89 | + $time = \DateTime::createFromFormat("U.u", number_format(microtime(true), 4, ".", "")); |
|
| 90 | + if ($time === false) { |
|
| 91 | + $time = new \DateTime(null, $timezone); |
|
| 92 | + } else { |
|
| 93 | + // apply timezone if $time is created from UNIX timestamp |
|
| 94 | + $time->setTimezone($timezone); |
|
| 95 | + } |
|
| 96 | + $request = \OC::$server->getRequest(); |
|
| 97 | + $reqId = $request->getId(); |
|
| 98 | + $remoteAddr = $request->getRemoteAddress(); |
|
| 99 | + // remove username/passwords from URLs before writing the to the log file |
|
| 100 | + $time = $time->format($format); |
|
| 101 | + $url = ($request->getRequestUri() !== '') ? $request->getRequestUri() : '--'; |
|
| 102 | + $method = is_string($request->getMethod()) ? $request->getMethod() : '--'; |
|
| 103 | + if($config->getValue('installed', false)) { |
|
| 104 | + $user = \OC_User::getUser() ? \OC_User::getUser() : '--'; |
|
| 105 | + } else { |
|
| 106 | + $user = '--'; |
|
| 107 | + } |
|
| 108 | + $userAgent = $request->getHeader('User-Agent'); |
|
| 109 | + if ($userAgent === '') { |
|
| 110 | + $userAgent = '--'; |
|
| 111 | + } |
|
| 112 | + $version = $config->getValue('version', ''); |
|
| 113 | + $entry = compact( |
|
| 114 | + 'reqId', |
|
| 115 | + 'level', |
|
| 116 | + 'time', |
|
| 117 | + 'remoteAddr', |
|
| 118 | + 'user', |
|
| 119 | + 'app', |
|
| 120 | + 'method', |
|
| 121 | + 'url', |
|
| 122 | + 'message', |
|
| 123 | + 'userAgent', |
|
| 124 | + 'version' |
|
| 125 | + ); |
|
| 126 | + // PHP's json_encode only accept proper UTF-8 strings, loop over all |
|
| 127 | + // elements to ensure that they are properly UTF-8 compliant or convert |
|
| 128 | + // them manually. |
|
| 129 | + foreach($entry as $key => $value) { |
|
| 130 | + if(is_string($value)) { |
|
| 131 | + $testEncode = json_encode($value); |
|
| 132 | + if($testEncode === false) { |
|
| 133 | + $entry[$key] = utf8_encode($value); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $entry = json_encode($entry, JSON_PARTIAL_OUTPUT_ON_ERROR); |
|
| 138 | + $handle = @fopen(self::$logFile, 'a'); |
|
| 139 | + if ((fileperms(self::$logFile) & 0777) != 0640) { |
|
| 140 | + @chmod(self::$logFile, 0640); |
|
| 141 | + } |
|
| 142 | + if ($handle) { |
|
| 143 | + fwrite($handle, $entry."\n"); |
|
| 144 | + fclose($handle); |
|
| 145 | + } else { |
|
| 146 | + // Fall back to error_log |
|
| 147 | + error_log($entry); |
|
| 148 | + } |
|
| 149 | + if (php_sapi_name() === 'cli-server') { |
|
| 150 | + error_log($message, 4); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - /** |
|
| 155 | - * get entries from the log in reverse chronological order |
|
| 156 | - * @param int $limit |
|
| 157 | - * @param int $offset |
|
| 158 | - * @return array |
|
| 159 | - */ |
|
| 160 | - public static function getEntries($limit=50, $offset=0) { |
|
| 161 | - self::init(); |
|
| 162 | - $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN); |
|
| 163 | - $entries = array(); |
|
| 164 | - $handle = @fopen(self::$logFile, 'rb'); |
|
| 165 | - if ($handle) { |
|
| 166 | - fseek($handle, 0, SEEK_END); |
|
| 167 | - $pos = ftell($handle); |
|
| 168 | - $line = ''; |
|
| 169 | - $entriesCount = 0; |
|
| 170 | - $lines = 0; |
|
| 171 | - // Loop through each character of the file looking for new lines |
|
| 172 | - while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) { |
|
| 173 | - fseek($handle, $pos); |
|
| 174 | - $ch = fgetc($handle); |
|
| 175 | - if ($ch == "\n" || $pos == 0) { |
|
| 176 | - if ($line != '') { |
|
| 177 | - // Add the first character if at the start of the file, |
|
| 178 | - // because it doesn't hit the else in the loop |
|
| 179 | - if ($pos == 0) { |
|
| 180 | - $line = $ch.$line; |
|
| 181 | - } |
|
| 182 | - $entry = json_decode($line); |
|
| 183 | - // Add the line as an entry if it is passed the offset and is equal or above the log level |
|
| 184 | - if ($entry->level >= $minLevel) { |
|
| 185 | - $lines++; |
|
| 186 | - if ($lines > $offset) { |
|
| 187 | - $entries[] = $entry; |
|
| 188 | - $entriesCount++; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - $line = ''; |
|
| 192 | - } |
|
| 193 | - } else { |
|
| 194 | - $line = $ch.$line; |
|
| 195 | - } |
|
| 196 | - $pos--; |
|
| 197 | - } |
|
| 198 | - fclose($handle); |
|
| 199 | - } |
|
| 200 | - return $entries; |
|
| 201 | - } |
|
| 154 | + /** |
|
| 155 | + * get entries from the log in reverse chronological order |
|
| 156 | + * @param int $limit |
|
| 157 | + * @param int $offset |
|
| 158 | + * @return array |
|
| 159 | + */ |
|
| 160 | + public static function getEntries($limit=50, $offset=0) { |
|
| 161 | + self::init(); |
|
| 162 | + $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN); |
|
| 163 | + $entries = array(); |
|
| 164 | + $handle = @fopen(self::$logFile, 'rb'); |
|
| 165 | + if ($handle) { |
|
| 166 | + fseek($handle, 0, SEEK_END); |
|
| 167 | + $pos = ftell($handle); |
|
| 168 | + $line = ''; |
|
| 169 | + $entriesCount = 0; |
|
| 170 | + $lines = 0; |
|
| 171 | + // Loop through each character of the file looking for new lines |
|
| 172 | + while ($pos >= 0 && ($limit === null ||$entriesCount < $limit)) { |
|
| 173 | + fseek($handle, $pos); |
|
| 174 | + $ch = fgetc($handle); |
|
| 175 | + if ($ch == "\n" || $pos == 0) { |
|
| 176 | + if ($line != '') { |
|
| 177 | + // Add the first character if at the start of the file, |
|
| 178 | + // because it doesn't hit the else in the loop |
|
| 179 | + if ($pos == 0) { |
|
| 180 | + $line = $ch.$line; |
|
| 181 | + } |
|
| 182 | + $entry = json_decode($line); |
|
| 183 | + // Add the line as an entry if it is passed the offset and is equal or above the log level |
|
| 184 | + if ($entry->level >= $minLevel) { |
|
| 185 | + $lines++; |
|
| 186 | + if ($lines > $offset) { |
|
| 187 | + $entries[] = $entry; |
|
| 188 | + $entriesCount++; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + $line = ''; |
|
| 192 | + } |
|
| 193 | + } else { |
|
| 194 | + $line = $ch.$line; |
|
| 195 | + } |
|
| 196 | + $pos--; |
|
| 197 | + } |
|
| 198 | + fclose($handle); |
|
| 199 | + } |
|
| 200 | + return $entries; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * @return string |
|
| 205 | - */ |
|
| 206 | - public static function getLogFilePath() { |
|
| 207 | - return self::$logFile; |
|
| 208 | - } |
|
| 203 | + /** |
|
| 204 | + * @return string |
|
| 205 | + */ |
|
| 206 | + public static function getLogFilePath() { |
|
| 207 | + return self::$logFile; |
|
| 208 | + } |
|
| 209 | 209 | } |