Commit b6f72c2d authored by Dave Marshall's avatar Dave Marshall Committed by Fabien Potencier

Lower the priority of the exception logging

parent c2148890
...@@ -70,6 +70,10 @@ class MonologServiceProvider implements ServiceProviderInterface ...@@ -70,6 +70,10 @@ class MonologServiceProvider implements ServiceProviderInterface
$app['monolog']->addInfo('> '.$request->getMethod().' '.$request->getRequestUri()); $app['monolog']->addInfo('> '.$request->getMethod().' '.$request->getRequestUri());
}); });
/*
* Priority -4 is used to come after those from SecurityServiceProvider (0)
* but before the error handlers added with Silex\Application::error (defaults to -8)
*/
$app->error(function (\Exception $e) use ($app) { $app->error(function (\Exception $e) use ($app) {
$message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()); $message = sprintf('%s: %s (uncaught exception) at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine());
if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) { if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
...@@ -77,7 +81,7 @@ class MonologServiceProvider implements ServiceProviderInterface ...@@ -77,7 +81,7 @@ class MonologServiceProvider implements ServiceProviderInterface
} else { } else {
$app['monolog']->addCritical($message, array('exception' => $e)); $app['monolog']->addCritical($message, array('exception' => $e));
} }
}, 255); }, -4);
$app->after(function (Request $request, Response $response) use ($app) { $app->after(function (Request $request, Response $response) use ($app) {
$app['monolog']->addInfo('< '.$response->getStatusCode()); $app['monolog']->addInfo('< '.$response->getStatusCode());
......
...@@ -94,6 +94,31 @@ class MonologServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -94,6 +94,31 @@ class MonologServiceProviderTest extends \PHPUnit_Framework_TestCase
$this->assertMatchingRecord($pattern, Logger::CRITICAL, $app['monolog.handler']); $this->assertMatchingRecord($pattern, Logger::CRITICAL, $app['monolog.handler']);
} }
public function testErrorLoggingGivesWayToSecurityExceptionHandling()
{
$app = $this->getApplication();
$app['monolog.level'] = Logger::ERROR;
$app->register(new \Silex\Provider\SecurityServiceProvider(), array(
'security.firewalls' => array(
'admin' => array(
'pattern' => '^/admin',
'http' => true,
'users' => array(),
),
),
));
$app->get("/admin", function () {
return "SECURE!";
});
$request = Request::create("/admin");
$app->run($request);
$this->assertEmpty($app['monolog.handler']->getRecords(), "Expected no logging to occur");
}
protected function assertMatchingRecord($pattern, $level, $handler) protected function assertMatchingRecord($pattern, $level, $handler)
{ {
$found = false; $found = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment