Commit 3f746692 authored by Gábor Fási's avatar Gábor Fási

Log the target url when redirecting

parent 4945dd0f
......@@ -15,6 +15,7 @@ use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Silex\Application;
use Silex\ServiceProviderInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bridge\Monolog\Handler\DebugHandler;
......@@ -84,7 +85,11 @@ class MonologServiceProvider implements ServiceProviderInterface
}, -4);
$app->after(function (Request $request, Response $response) use ($app) {
$app['monolog']->addInfo('< '.$response->getStatusCode());
if ($response instanceof RedirectResponse) {
$app['monolog']->addInfo('< '.$response->getStatusCode() . ' ' . $response->getTargetUrl());
} else {
$app['monolog']->addInfo('< '.$response->getStatusCode());
}
});
}
}
......@@ -15,6 +15,7 @@ use Monolog\Handler\TestHandler;
use Monolog\Logger;
use Silex\Application;
use Silex\Provider\MonologServiceProvider;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -94,6 +95,22 @@ class MonologServiceProviderTest extends \PHPUnit_Framework_TestCase
$this->assertMatchingRecord($pattern, Logger::CRITICAL, $app['monolog.handler']);
}
public function testRedirectLogging()
{
$app = $this->getApplication();
$app->get('/foo', function () use ($app) {
return new RedirectResponse("/bar", 302);
});
$this->assertFalse($app['monolog.handler']->hasInfoRecords());
$request = Request::create('/foo');
$app->handle($request);
$this->assertTrue($app['monolog.handler']->hasInfo('< 302 /bar'));
}
public function testErrorLoggingGivesWayToSecurityExceptionHandling()
{
$app = $this->getApplication();
......
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