|
62 | 62 | * MonoLog is an example implementing this interface. |
63 | 63 | */ |
64 | 64 | class Log implements ILogger, IDataLogger { |
65 | | - private IWriter $logger; |
66 | 65 | private ?SystemConfig $config; |
67 | 66 | private ?bool $logConditionSatisfied = null; |
68 | 67 | private ?Normalizer $normalizer; |
69 | | - private ?IRegistry $crashReporters; |
70 | 68 | private ?IEventDispatcher $eventDispatcher; |
71 | 69 |
|
72 | 70 | /** |
73 | 71 | * @param IWriter $logger The logger that should be used |
74 | | - * @param SystemConfig $config the system config object |
| 72 | + * @param SystemConfig|null $config the system config object |
75 | 73 | * @param Normalizer|null $normalizer |
76 | | - * @param IRegistry|null $registry |
| 74 | + * @param IRegistry|null $crashReporters |
77 | 75 | */ |
78 | 76 | public function __construct( |
79 | | - IWriter $logger, |
| 77 | + private IWriter $logger, |
80 | 78 | SystemConfig $config = null, |
81 | 79 | Normalizer $normalizer = null, |
82 | | - IRegistry $registry = null |
| 80 | + private ?IRegistry $crashReporters = null |
83 | 81 | ) { |
84 | 82 | // FIXME: Add this for backwards compatibility, should be fixed at some point probably |
85 | 83 | if ($config === null) { |
86 | 84 | $config = \OC::$server->getSystemConfig(); |
87 | 85 | } |
88 | 86 |
|
89 | 87 | $this->config = $config; |
90 | | - $this->logger = $logger; |
91 | 88 | if ($normalizer === null) { |
92 | 89 | $this->normalizer = new Normalizer(); |
93 | 90 | } else { |
94 | 91 | $this->normalizer = $normalizer; |
95 | 92 | } |
96 | | - $this->crashReporters = $registry; |
97 | 93 | $this->eventDispatcher = null; |
98 | 94 | } |
99 | 95 |
|
@@ -211,6 +207,9 @@ public function debug(string $message, array $context = []) { |
211 | 207 | */ |
212 | 208 | public function log(int $level, string $message, array $context = []) { |
213 | 209 | $minLevel = $this->getLogLevel($context); |
| 210 | + if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) { |
| 211 | + return; // we already know that log will be fully ignored |
| 212 | + } |
214 | 213 |
|
215 | 214 | array_walk($context, [$this->normalizer, 'format']); |
216 | 215 |
|
@@ -241,9 +240,7 @@ public function log(int $level, string $message, array $context = []) { |
241 | 240 | $this->crashReporters->delegateMessage($entry['message'], $messageContext); |
242 | 241 | } |
243 | 242 | } else { |
244 | | - if ($this->crashReporters !== null) { |
245 | | - $this->crashReporters->delegateBreadcrumb($entry['message'], 'log', $context); |
246 | | - } |
| 243 | + $this->crashReporters?->delegateBreadcrumb($entry['message'], 'log', $context); |
247 | 244 | } |
248 | 245 | } catch (Throwable $e) { |
249 | 246 | // make sure we dont hard crash if logging fails |
@@ -329,8 +326,8 @@ public function logException(Throwable $exception, array $context = []) { |
329 | 326 | $level = $context['level'] ?? ILogger::ERROR; |
330 | 327 |
|
331 | 328 | $minLevel = $this->getLogLevel($context); |
332 | | - if ($level < $minLevel && ($this->crashReporters === null || !$this->crashReporters->hasReporters())) { |
333 | | - return; |
| 329 | + if ($level < $minLevel && (($this->crashReporters?->hasReporters() ?? false) === false)) { |
| 330 | + return; // we already know that log will be fully ignored |
334 | 331 | } |
335 | 332 |
|
336 | 333 | // if an error is raised before the autoloader is properly setup, we can't serialize exceptions |
|
0 commit comments