From 00b7575c89815aa218e7e3ed3d61b25ee65f244f Mon Sep 17 00:00:00 2001 From: Julius Härtl Date: Tue, 3 Jan 2023 19:03:57 +0100 Subject: perf(logging): Return early when log level does not match before serializing an exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Log.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib/private/Log.php') diff --git a/lib/private/Log.php b/lib/private/Log.php index 4ab647bc6c1..e4be5134f11 100644 --- a/lib/private/Log.php +++ b/lib/private/Log.php @@ -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']); -- cgit v1.2.3