Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2022-07-07 12:47:34 +0300
committerGitHub <noreply@github.com>2022-07-07 12:47:34 +0300
commitb3ee9b7b985131d55f1d3d40fa701220538bd1e5 (patch)
treebce2e557961088d70bb48ea35d9f68e5e0936224 /lib
parent0164dffcd32c3da75e9458616667c416cfb47288 (diff)
parent08035833cf25c203fba4ba52dbd692df8fba09fb (diff)
Merge pull request #32983 from nextcloud/backport/32242/stable24
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Log.php34
-rw-r--r--lib/private/Log/LogDetails.php4
2 files changed, 24 insertions, 14 deletions
diff --git a/lib/private/Log.php b/lib/private/Log.php
index 0415967f0f0..95e0a833b66 100644
--- a/lib/private/Log.php
+++ b/lib/private/Log.php
@@ -15,6 +15,7 @@ declare(strict_types=1);
* @author Olivier Paroz <github@oparoz.com>
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Victor Dubiniuk <dubiniuk@owncloud.com>
*
@@ -207,11 +208,11 @@ class Log implements ILogger, IDataLogger {
array_walk($context, [$this->normalizer, 'format']);
$app = $context['app'] ?? 'no app in context';
- $message = $this->interpolateMessage($context, $message);
+ $entry = $this->interpolateMessage($context, $message);
try {
if ($level >= $minLevel) {
- $this->writeLog($app, $message, $level);
+ $this->writeLog($app, $entry, $level);
if ($this->crashReporters !== null) {
$messageContext = array_merge(
@@ -220,11 +221,11 @@ class Log implements ILogger, IDataLogger {
'level' => $level
]
);
- $this->crashReporters->delegateMessage($message, $messageContext);
+ $this->crashReporters->delegateMessage($entry['message'], $messageContext);
}
} else {
if ($this->crashReporters !== null) {
- $this->crashReporters->delegateBreadcrumb($message, 'log', $context);
+ $this->crashReporters->delegateBreadcrumb($entry['message'], 'log', $context);
}
}
} catch (\Throwable $e) {
@@ -315,8 +316,11 @@ class Log implements ILogger, IDataLogger {
$this->error("Failed to load ExceptionSerializer serializer while trying to log " . $exception->getMessage());
return;
}
- $data = $serializer->serializeException($exception);
- $data['CustomMessage'] = $this->interpolateMessage($context, $context['message'] ?? '--');
+ $data = $context;
+ unset($data['app']);
+ unset($data['level']);
+ $data = array_merge($serializer->serializeException($exception), $data);
+ $data = $this->interpolateMessage($data, $context['message'] ?? '--', 'CustomMessage');
$minLevel = $this->getLogLevel($context);
@@ -381,16 +385,20 @@ class Log implements ILogger, IDataLogger {
/**
* Interpolate $message as defined in PSR-3
*
- * @param array $context
- * @param string $message
- *
- * @return string
+ * Returns an array containing the context without the interpolated
+ * parameters placeholders and the message as the 'message' - or
+ * user-defined - key.
*/
- private function interpolateMessage(array $context, string $message): string {
+ private function interpolateMessage(array $context, string $message, string $messageKey = 'message'): array {
$replace = [];
+ $usedContextKeys = [];
foreach ($context as $key => $val) {
- $replace['{' . $key . '}'] = $val;
+ $fullKey = '{' . $key . '}';
+ $replace[$fullKey] = $val;
+ if (strpos($message, $fullKey) !== false) {
+ $usedContextKeys[$key] = true;
+ }
}
- return strtr($message, $replace);
+ return array_merge(array_diff_key($context, $usedContextKeys), [$messageKey => strtr($message, $replace)]);
}
}
diff --git a/lib/private/Log/LogDetails.php b/lib/private/Log/LogDetails.php
index 3353ea3f4cc..b3544572708 100644
--- a/lib/private/Log/LogDetails.php
+++ b/lib/private/Log/LogDetails.php
@@ -5,6 +5,7 @@
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Julius Härtl <jus@bitgrid.net>
+ * @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
@@ -90,8 +91,9 @@ abstract class LogDetails {
$entry['exception'] = $message;
$entry['message'] = $message['CustomMessage'] !== '--' ? $message['CustomMessage'] : $message['Message'];
} else {
- $entry['data'] = $message;
$entry['message'] = $message['message'] ?? '(no message provided)';
+ unset($message['message']);
+ $entry['data'] = $message;
}
}