|
44 | 44 | use OCP\Log\IFileBased; |
45 | 45 | use OCP\Log\IWriter; |
46 | 46 | use OCP\Support\CrashReport\IRegistry; |
| 47 | +use function strtr; |
47 | 48 |
|
48 | 49 | /** |
49 | 50 | * logging utilities |
@@ -207,13 +208,7 @@ public function log(int $level, string $message, array $context = []) { |
207 | 208 | array_walk($context, [$this->normalizer, 'format']); |
208 | 209 |
|
209 | 210 | $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); |
217 | 212 |
|
218 | 213 | try { |
219 | 214 | if ($level >= $minLevel) { |
@@ -316,7 +311,7 @@ public function logException(\Throwable $exception, array $context = []) { |
316 | 311 |
|
317 | 312 | $serializer = new ExceptionSerializer($this->config); |
318 | 313 | $data = $serializer->serializeException($exception); |
319 | | - $data['CustomMessage'] = $context['message'] ?? '--'; |
| 314 | + $data['CustomMessage'] = $this->interpolateMessage($context, $context['message'] ?? '--'); |
320 | 315 |
|
321 | 316 | $minLevel = $this->getLogLevel($context); |
322 | 317 |
|
@@ -377,4 +372,20 @@ public function getLogPath():string { |
377 | 372 | } |
378 | 373 | throw new \RuntimeException('Log implementation has no path'); |
379 | 374 | } |
| 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 | + } |
380 | 391 | } |
0 commit comments