Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
3f746692
Commit
3f746692
authored
Jul 26, 2013
by
Gábor Fási
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log the target url when redirecting
parent
4945dd0f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
1 deletion
+23
-1
src/Silex/Provider/MonologServiceProvider.php
src/Silex/Provider/MonologServiceProvider.php
+6
-1
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
+17
-0
No files found.
src/Silex/Provider/MonologServiceProvider.php
View file @
3f746692
...
...
@@ -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
());
}
});
}
}
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
View file @
3f746692
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment