Skip to content

Commit dbdc814

Browse files
authored
Merge pull request #29963 from nextcloud/backport/29951/stable21
2 parents 064f261 + 603d623 commit dbdc814

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

lib/private/Log.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use OCP\Log\IFileBased;
4545
use OCP\Log\IWriter;
4646
use OCP\Support\CrashReport\IRegistry;
47+
use function strtr;
4748

4849
/**
4950
* logging utilities
@@ -207,13 +208,7 @@ public function log(int $level, string $message, array $context = []) {
207208
array_walk($context, [$this->normalizer, 'format']);
208209

209210
$app = $context['app'] ?? 'no app in context';
210-
211-
// interpolate $message as defined in PSR-3
212-
$replace = [];
213-
foreach ($context as $key => $val) {
214-
$replace['{' . $key . '}'] = $val;
215-
}
216-
$message = strtr($message, $replace);
211+
$message = $this->interpolateMessage($context, $message);
217212

218213
try {
219214
if ($level >= $minLevel) {
@@ -316,7 +311,7 @@ public function logException(\Throwable $exception, array $context = []) {
316311

317312
$serializer = new ExceptionSerializer($this->config);
318313
$data = $serializer->serializeException($exception);
319-
$data['CustomMessage'] = $context['message'] ?? '--';
314+
$data['CustomMessage'] = $this->interpolateMessage($context, $context['message'] ?? '--');
320315

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

@@ -377,4 +372,20 @@ public function getLogPath():string {
377372
}
378373
throw new \RuntimeException('Log implementation has no path');
379374
}
375+
376+
/**
377+
* Interpolate $message as defined in PSR-3
378+
*
379+
* @param array $context
380+
* @param string $message
381+
*
382+
* @return string
383+
*/
384+
private function interpolateMessage(array $context, string $message): string {
385+
$replace = [];
386+
foreach ($context as $key => $val) {
387+
$replace['{' . $key . '}'] = $val;
388+
}
389+
return strtr($message, $replace);
390+
}
380391
}

0 commit comments

Comments
 (0)