1 | <?php |
||
42 | class Reporter implements MiddlewareInterface, LoggerAwareInterface |
||
43 | { |
||
44 | use LoggerAwareTrait; |
||
45 | |||
46 | /** |
||
47 | * @var array<string,string> Stores the Exception class name to log level |
||
48 | */ |
||
49 | private $levels; |
||
50 | |||
51 | /** |
||
52 | * Creates a new Reporter middleware. |
||
53 | * |
||
54 | * If an exception isn't found in the `$levels` map, this class assumes a |
||
55 | * level of `LogLevel::ERROR`. |
||
56 | * |
||
57 | * ```php |
||
58 | * $elog = new ErrorLogger( |
||
59 | * $logger, |
||
60 | * ["MyException" => LogLevel::DEBUG, "RuntimeException" => LogLevel::WARN] |
||
61 | * ); |
||
62 | * ``` |
||
63 | * |
||
64 | * @param \Psr\Log\LoggerInterface|null $logger The logger; will use `Psr\Log\NullLogger` by default |
||
65 | * @param array|null $levels Map of Exception names to log levels. Order matters! |
||
66 | */ |
||
67 | 3 | public function __construct(LoggerInterface $logger = null, array $levels = null) |
|
74 | |||
75 | /** |
||
76 | * {@inheritDoc} |
||
77 | * |
||
78 | * If the logger throws an exception, it's silently discarded. |
||
79 | */ |
||
80 | 3 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
100 | } |
||
101 |