Browse Source

perf(logging): Return early when log level does not match before serializing an exception

Signed-off-by: Julius Härtl <jus@bitgrid.net>
tags/v26.0.0beta1
Julius Härtl 1 year ago
parent
commit
00b7575c89
No account linked to committer's email address

+ 5
- 1
lib/private/Log.php View File

@@ -312,6 +312,11 @@ class Log implements ILogger, IDataLogger {
$app = $context['app'] ?? 'no app in context';
$level = $context['level'] ?? ILogger::ERROR;

$minLevel = $this->getLogLevel($context);
if ($level < $minLevel && ($this->crashReporters === null || !$this->crashReporters->hasReporters())) {
return;
}

// if an error is raised before the autoloader is properly setup, we can't serialize exceptions
try {
$serializer = $this->getSerializer();
@@ -325,7 +330,6 @@ class Log implements ILogger, IDataLogger {
$data = array_merge($serializer->serializeException($exception), $data);
$data = $this->interpolateMessage($data, $context['message'] ?? '--', 'CustomMessage');

$minLevel = $this->getLogLevel($context);

array_walk($context, [$this->normalizer, 'format']);


+ 4
- 0
lib/private/Support/CrashReport/Registry.php View File

@@ -147,4 +147,8 @@ class Registry implements IRegistry {
}
}
}

public function hasReporters(): bool {
return !empty($this->lazyReporters) || !empty($this->reporters);
}
}

+ 9
- 0
lib/public/Support/CrashReport/IRegistry.php View File

@@ -81,4 +81,13 @@ interface IRegistry {
* @since 17.0.0
*/
public function delegateMessage(string $message, array $context = []): void;

/**
* Check if any reporter has been registered to delegate to
*
* @return bool
* @deprecated use internally only
* @since 26.0.0
*/
public function hasReporters(): bool;
}

Loading…
Cancel
Save