mirror of
https://github.com/nextcloud/server.git
synced 2024-09-03 05:56:02 +02:00
Merge pull request #29951 from nextcloud/fix/log-interpolation-exceptions
Interpolate the log message also for logged exceptions
This commit is contained in:
commit
c9a1937eb9
@ -43,6 +43,7 @@ use OCP\ILogger;
|
||||
use OCP\Log\IFileBased;
|
||||
use OCP\Log\IWriter;
|
||||
use OCP\Support\CrashReport\IRegistry;
|
||||
use function strtr;
|
||||
|
||||
/**
|
||||
* logging utilities
|
||||
@ -206,13 +207,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) {
|
||||
@ -315,7 +310,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);
|
||||
|
||||
@ -376,4 +371,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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user