summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2022-01-07 08:48:20 +0100
committerGitHub <noreply@github.com>2022-01-07 08:48:20 +0100
commitdbdc814e81ff71b4280d5d92e5acc3f41afbe8d9 (patch)
treee2226a482926df7b32545f432fa6cbe505c01979
parent064f2615d74cdbe10f0ff56cb45a11066767991f (diff)
parent603d623d545f4f84d4f6a8c374ed2c54c4746b0a (diff)
downloadnextcloud-server-dbdc814e81ff71b4280d5d92e5acc3f41afbe8d9.tar.gz
nextcloud-server-dbdc814e81ff71b4280d5d92e5acc3f41afbe8d9.zip
Merge pull request #29963 from nextcloud/backport/29951/stable21
-rw-r--r--lib/private/Log.php27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php
index db86aa8bfe3..3c3f22293d9 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -44,6 +44,7 @@ use OCP\ILogger;
use OCP\Log\IFileBased;
use OCP\Log\IWriter;
use OCP\Support\CrashReport\IRegistry;
+use function strtr;
/**
* logging utilities
@@ -207,13 +208,7 @@ class Log implements ILogger, IDataLogger {
array_walk($context, [$this->normalizer, 'format']);
$app = $context['app'] ?? 'no app in context';
-
- // interpolate $message as defined in PSR-3
- $replace = [];
- foreach ($context as $key => $val) {
- $replace['{' . $key . '}'] = $val;
- }
- $message = strtr($message, $replace);
+ $message = $this->interpolateMessage($context, $message);
try {
if ($level >= $minLevel) {
@@ -316,7 +311,7 @@ class Log implements ILogger, IDataLogger {
$serializer = new ExceptionSerializer($this->config);
$data = $serializer->serializeException($exception);
- $data['CustomMessage'] = $context['message'] ?? '--';
+ $data['CustomMessage'] = $this->interpolateMessage($context, $context['message'] ?? '--');
$minLevel = $this->getLogLevel($context);
@@ -377,4 +372,20 @@ class Log implements ILogger, IDataLogger {
}
throw new \RuntimeException('Log implementation has no path');
}
+
+ /**
+ * Interpolate $message as defined in PSR-3
+ *
+ * @param array $context
+ * @param string $message
+ *
+ * @return string
+ */
+ private function interpolateMessage(array $context, string $message): string {
+ $replace = [];
+ foreach ($context as $key => $val) {
+ $replace['{' . $key . '}'] = $val;
+ }
+ return strtr($message, $replace);
+ }
}