1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace WyriHaximus\PSR3\CallableThrowableLogger; |
||
6 | |||
7 | use Psr\Log\LoggerInterface; |
||
8 | use Throwable; |
||
9 | |||
10 | use function sprintf; |
||
11 | |||
12 | final class CallableThrowableLogger |
||
13 | { |
||
14 | 2 | public const string MESSAGE = 'Uncaught Throwable %1$s: "%2$s" at %3$s line %4$s'; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
15 | 2 | ||
16 | 2 | public static function create(LoggerInterface $logger, string $level = 'error', string $message = self::MESSAGE): callable |
|
17 | 2 | { |
|
18 | 2 | return static function (Throwable $throwable) use ($logger, $level, $message): void { |
|
19 | 2 | /** |
|
20 | 2 | * Ignoring this because we're just passing it a long |
|
21 | 2 | * |
|
22 | 2 | * @phpstan-ignore psr3.interpolated,shipmonk.checkedExceptionInCallable |
|
23 | */ |
||
24 | $logger->log( |
||
25 | 2 | $level, |
|
26 | sprintf( |
||
27 | $message, |
||
28 | 2 | $throwable::class, // phpcs:disable |
|
29 | $throwable->getMessage(), |
||
30 | $throwable->getFile(), |
||
31 | $throwable->getLine() |
||
32 | ), |
||
33 | ['exception' => $throwable] |
||
34 | ); |
||
35 | }; |
||
36 | } |
||
37 | } |
||
38 |