-
Hey, I have some exceptions I don't want to log as What I'm doing now is a custom registering a custom reportable callback in the exception handler and use a custom logging there. $this->reportable(function (FatalError $e): void {
$logger = $this->container->make(LoggerInterface::class);
$logger->critical(
$e->getMessage(),
array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
)
);
})->stop(); this works totally fine - but it feels wrong as I copy that whole context stuff from the core How about a property like the protected array $reportLevel = [
\Symfony\Component\ErrorHandler\Error\FatalError => \Psr\Log\LogLevel::CRITICAL,
\PDOException => \Psr\Log\LogLevel::ALERT,
]; In the core handler this could be used like the following: $level = Arr::first($this->reportLevel, function (string $level, string $type) use ($e) {
return $e instanceof $type;
}, LogLevel::ERROR);
$logger->log(
$level,
$e->getMessage(),
array_merge(
$this->exceptionContext($e),
$this->context(),
['exception' => $e]
)
); This would still log everything as error by default - but if there's a custom level defined it will use that one. That idea could even be extended to a new interface which will allow to define the level on the exception itself - like the already existing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
PR: #41925 |
Beta Was this translation helpful? Give feedback.
PR: #41925