silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

RFC: Lowering priority on monolog exception logging #752

Closed davedevelopment closed 11 years ago

davedevelopment commented 11 years ago

Currently the monolog service provider adds an error handler to log exceptions at a priority of 255, which means it comes in before the security providers exception handlers, so AccessDeniedExceptions get logged as critical events by monolog, when really they're kind of expected and handled by the security provider.

Example:


<?php

require "vendor/autoload.php";

$app = new Silex\Application;
$app->register(new Silex\Provider\MonologServiceProvider(), [
    'monolog.logfile' => 'php://stderr',
    'monolog.level' => Monolog\Logger::ERROR,                         
]);

$app->register(new Silex\Provider\SecurityServiceProvider(), [
    'security.firewalls' => [
        'admin' => [
            'pattern' => '^/admin',
            'http' => true,
            'users' => [],
        ],
    ],
]);

$app->get("/admin", function () {
    return "SECURE!";
});

$request = Symfony\Component\HttpFoundation\Request::create("/admin");

$app->run($request);

EDIT: Sample output

[2013-07-16 21:23:27] myapp.CRITICAL: Symfony\Component\Security\Core\Exception\AuthenticationCredentialsNotFoundException: A Token was not found in the SecurityContext. (uncaught exception) at /home/davem/src/Silex/vendor/symfony/security/Symfony/Component/Security/Http/Firewall/AccessListener.php line 56 {"exception":"[object] (Symfony\\Component\\Security\\Core\\Exception\\AuthenticationCredentialsNotFoundException: A Token was not found in the SecurityContext. at /home/davem/src/Silex/vendor/symfony/security/Symfony/Component/Security/Http/Firewall/AccessListener.php:56)"} []

I don't think this is ideal behaviour out of the box, what are other peoples thoughts?

DerManoMann commented 11 years ago

I agree - I always wondered why all those exceptions were in the log for things that are not wrong - iirc this also happens for requests that are authenticated via remember-me. :+1: to change this (I am open to other solutions as I am not too familiar with the priorities ...)

fabpot commented 11 years ago

I agree