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
b6f72c2d
Commit
b6f72c2d
authored
Jul 18, 2013
by
Dave Marshall
Committed by
Fabien Potencier
Jul 19, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Lower the priority of the exception logging
parent
c2148890
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
src/Silex/Provider/MonologServiceProvider.php
src/Silex/Provider/MonologServiceProvider.php
+5
-1
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
+25
-0
No files found.
src/Silex/Provider/MonologServiceProvider.php
View file @
b6f72c2d
...
@@ -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
());
...
...
tests/Silex/Tests/Provider/MonologServiceProviderTest.php
View file @
b6f72c2d
...
@@ -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
;
...
...
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