Commit 94f4855b authored by Fabien Potencier's avatar Fabien Potencier

minor #1430 Test/Explain monolog.exception.logger_filter (SpacePossum)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Test/Explain monolog.exception.logger_filter

This PR:
- adds a test for the `monolog.exception.logger_filter` configuration option for the MonologServiceProvider
- updates the description stating it is not a filter, but a mapping function from exception to error level

Commits
-------

21bd1c42 Test/Explain monolog.exception.logger_filter
parents 2b2fabb3 21bd1c42
......@@ -29,7 +29,7 @@ Parameters
defaults to ``myapp``.
* **monolog.exception.logger_filter** (optional): An anonymous function that
filters which exceptions should be logged.
returns an error level for on uncaught exception that should be logged.
* **monolog.use_error_handler** (optional): Whether errors and uncaught exceptions
should be handled by the Monolog ``ErrorHandler`` class and added to the log.
......
......@@ -18,6 +18,7 @@ use Silex\Application;
use Silex\Provider\MonologServiceProvider;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Kernel;
/**
......@@ -109,7 +110,6 @@ class MonologServiceProviderTest extends \PHPUnit_Framework_TestCase
$request = Request::create('/error');
$app->handle($request);
$records = $app['monolog.handler']->getRecords();
$pattern = "#Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\NotFoundHttpException: No route found for \"GET /error\" \(uncaught exception\) at .* line \d+#";
$this->assertMatchingRecord($pattern, Logger::ERROR, $app['monolog.handler']);
......@@ -200,7 +200,32 @@ class MonologServiceProviderTest extends \PHPUnit_Framework_TestCase
$this->assertEmpty($app['monolog.handler']->getRecords(), 'Expected no logging to occur');
}
protected function assertMatchingRecord($pattern, $level, $handler)
public function testExceptionFiltering()
{
$app = new Application();
$app->get('/foo', function () use ($app) {
throw new NotFoundHttpException();
});
$level = Logger::ERROR;
$app->register(new MonologServiceProvider(), array(
'monolog.exception.logger_filter' => $app->protect(function () {
return Logger::DEBUG;
}),
'monolog.handler' => function () use ($app) {
return new TestHandler($app['monolog.level']);
},
'monolog.level' => $level,
'monolog.logfile' => 'php://memory',
));
$request = Request::create('/foo');
$app->handle($request);
$this->assertCount(0, $app['monolog.handler']->getRecords(), 'Expected no logging to occur');
}
protected function assertMatchingRecord($pattern, $level, TestHandler $handler)
{
$found = false;
$records = $handler->getRecords();
......
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