Skip to content

Commit fe816f8

Browse files
committed
Fix: Psr-Logger exception-handling
1 parent 9116e17 commit fe816f8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

library/Notifications/Common/PsrLogger.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,24 @@ public function log($level, $message, array $context = []): void
4747
$level = strtolower((string) $level);
4848
$icingaMethod = self::MAP[$level] ?? 'debug';
4949

50-
array_unshift($context, $message);
50+
$parsedContext = [];
51+
if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
52+
$parsedContext[] = $context['exception']->getTraceAsString();
53+
}
54+
array_unshift($parsedContext, (string) $message);
5155

5256
switch ($icingaMethod) {
5357
case 'error':
54-
IcingaLogger::error(...$context);
58+
IcingaLogger::error(...$parsedContext);
5559
break;
5660
case 'warning':
57-
IcingaLogger::warning(...$context);
61+
IcingaLogger::warning(...$parsedContext);
5862
break;
5963
case 'info':
60-
IcingaLogger::info(...$context);
64+
IcingaLogger::info(...$parsedContext);
6165
break;
6266
default:
63-
IcingaLogger::debug(...$context);
67+
IcingaLogger::debug(...$parsedContext);
6468
break;
6569
}
6670
}

0 commit comments

Comments
 (0)