-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handled exceptions being logged as critical #2270
Comments
Which version do you use? Can you create a small example application that allows to reproduce your issue? |
Sure, @xabbuh, I think here are all the relevant parts: Using: config/packages/monolog.yaml
config/packages/fos_rest.yaml
src/Controller/Open/TestController
and after browsing that route we get: Response, perfect, as expected:
but also this line in var/log/prod.log:
which is the line I would like to avoid. |
Hi Any news on this ? I'm facing the same issue Or @xDaizu, did you find a way to avoid the error logging ? |
Similar situation handled exception in fos_rest.yaml returns code 400 but still Uncaught PHP Exception occurs. Any news ? |
This might be the same issue like this one -- #2369 It's still very much an issue, has anyone found a workaround? |
@WissameMekhilef my workaround was to implement an ActivationStrategyInterface to filter the exceptions processed by Monolog. Here's a code snippet: namespace App\Infrastructure\Logging;
use Doctrine\ORM\EntityNotFoundException;
use Monolog\Handler\FingersCrossed\ActivationStrategyInterface;
use Monolog\Level;
use Monolog\LogRecord;
use Symfony\Component\HttpFoundation\RequestStack;
class MonologApiLoggingStrategy implements ActivationStrategyInterface
{
public function __construct(private RequestStack $requestStack)
{
}
public function isHandlerActivated(LogRecord $record): bool
{
$request = $this->requestStack->getMainRequest();
if ($request && preg_match('/^\/api/', $request->getPathInfo())) {
if (
isset($record->context['exception'])
&&
(
$record->context['exception'] instanceof \InvalidArgumentException
|| $record->context['exception'] instanceof EntityNotFoundException
)
) {
return false;
}
}
return $record['level'] >= Level::Critical;
}
} |
Not sure if this helps, but the logging should be entering in monolog.nested part, where you can exclude via channels in that prod.log file generated with the name of the controller specifically, with your example it should be: monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
excluded_http_codes: [404, 405]
buffer_size: 50
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: ["!event", "!doctrine", "!TestController"]
console:
type: console
process_psr_3_messages: false
channels: ["!event", "!doctrine"] |
I am configuring the FOSRest Bundle to handle domain exceptions as shown in:
https://symfony.com/doc/current/bundles/FOSRestBundle/4-exception-controller-support.html
But exceptions are still logged as
which is logged by the default
Symfony\Component\HttpKernel\EventListener\ErrorListener::logKernelException
listener.I think this is contrary to the design philosophy of the exception controller, which is effectively handling the exception by deciding to return an error code and a message to the browser.
Is there any way to avoid this and prevent logging exceptions that ARE known and handled by the FOSRestBundle?
The text was updated successfully, but these errors were encountered: