Command
2 months ago
Formatter
1 year ago
Handler
2 months ago
Messenger
2 years ago
Processor
1 year ago
LICENSE
2 years ago
Logger.php
2 years ago
README.md
2 years ago
Logger.php
93 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | namespace Matomo\Dependencies\Symfony\Bridge\Monolog; |
| 12 | |
| 13 | use Matomo\Dependencies\Monolog\Logger as BaseLogger; |
| 14 | use Matomo\Dependencies\Monolog\ResettableInterface; |
| 15 | use Matomo\Dependencies\Symfony\Component\HttpFoundation\Request; |
| 16 | use Matomo\Dependencies\Symfony\Component\HttpKernel\Log\DebugLoggerInterface; |
| 17 | use Matomo\Dependencies\Symfony\Contracts\Service\ResetInterface; |
| 18 | /** |
| 19 | * @author Fabien Potencier <fabien@symfony.com> |
| 20 | */ |
| 21 | class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface |
| 22 | { |
| 23 | /** |
| 24 | * {@inheritdoc} |
| 25 | */ |
| 26 | public function getLogs(?Request $request = null) |
| 27 | { |
| 28 | if ($logger = $this->getDebugLogger()) { |
| 29 | return $logger->getLogs($request); |
| 30 | } |
| 31 | return []; |
| 32 | } |
| 33 | /** |
| 34 | * {@inheritdoc} |
| 35 | */ |
| 36 | public function countErrors(?Request $request = null) |
| 37 | { |
| 38 | if ($logger = $this->getDebugLogger()) { |
| 39 | return $logger->countErrors($request); |
| 40 | } |
| 41 | return 0; |
| 42 | } |
| 43 | /** |
| 44 | * {@inheritdoc} |
| 45 | */ |
| 46 | public function clear() |
| 47 | { |
| 48 | if ($logger = $this->getDebugLogger()) { |
| 49 | $logger->clear(); |
| 50 | } |
| 51 | } |
| 52 | /** |
| 53 | * {@inheritdoc} |
| 54 | */ |
| 55 | public function reset() : void |
| 56 | { |
| 57 | $this->clear(); |
| 58 | if ($this instanceof ResettableInterface) { |
| 59 | parent::reset(); |
| 60 | } |
| 61 | } |
| 62 | public function removeDebugLogger() |
| 63 | { |
| 64 | foreach ($this->processors as $k => $processor) { |
| 65 | if ($processor instanceof DebugLoggerInterface) { |
| 66 | unset($this->processors[$k]); |
| 67 | } |
| 68 | } |
| 69 | foreach ($this->handlers as $k => $handler) { |
| 70 | if ($handler instanceof DebugLoggerInterface) { |
| 71 | unset($this->handlers[$k]); |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | /** |
| 76 | * Returns a DebugLoggerInterface instance if one is registered with this logger. |
| 77 | */ |
| 78 | private function getDebugLogger() : ?DebugLoggerInterface |
| 79 | { |
| 80 | foreach ($this->processors as $processor) { |
| 81 | if ($processor instanceof DebugLoggerInterface) { |
| 82 | return $processor; |
| 83 | } |
| 84 | } |
| 85 | foreach ($this->handlers as $handler) { |
| 86 | if ($handler instanceof DebugLoggerInterface) { |
| 87 | return $handler; |
| 88 | } |
| 89 | } |
| 90 | return null; |
| 91 | } |
| 92 | } |
| 93 |