Skip to content
Permalink
Browse files

Only log exception attributes when debug is on.

Elide the exception attributes when debug is false.

Refs #6957
  • Loading branch information...
markstory committed Jul 7, 2015
1 parent c7e5712 commit 91a18c2e172132e61e7a776e36f1e3409adc49f1
Showing with 43 additions and 1 deletion.
  1. +3 −1 src/Error/BaseErrorHandler.php
  2. +40 −0 tests/TestCase/Error/ErrorHandlerTest.php
@@ -259,7 +259,9 @@ protected function _getMessage(\Exception $exception)
get_class($exception),
$exception->getMessage()
);
if (method_exists($exception, 'getAttributes')) {
$debug = Configure::read('debug');
if ($debug && method_exists($exception, 'getAttributes')) {
$attributes = $exception->getAttributes();
if ($attributes) {
$message .= "\nException Attributes: " . var_export($exception->getAttributes(), true);
@@ -26,6 +26,7 @@
use Cake\Network\Exception\NotFoundException;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Routing\Exception\MissingControllerException;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
@@ -280,6 +281,45 @@ public function testHandleExceptionLog()
$errorHandler->handleException($error);
}
/**
* test logging attributes with/without debug
*
* @return void
*/
public function testHandleExceptionLogAttributes()
{
$errorHandler = new TestErrorHandler([
'log' => true,
'trace' => true,
]);
$error = new MissingControllerException(['class' => 'Derp']);
$this->_logger->expects($this->at(0))
->method('log')
->with('error', $this->logicalAnd(
$this->stringContains(
'[Cake\Routing\Exception\MissingControllerException] ' .
'Controller class Derp could not be found.'
),
$this->stringContains('Exception Attributes:')
));
$this->_logger->expects($this->at(1))
->method('log')
->with('error', $this->logicalAnd(
$this->stringContains(
'[Cake\Routing\Exception\MissingControllerException] ' .
'Controller class Derp could not be found.'
),
$this->logicalNot($this->stringContains('Exception Attributes:'))
));
$errorHandler->handleException($error);
Configure::write('debug', false);
$errorHandler->handleException($error);
}
/**
* test handleException generating log.
*

0 comments on commit 91a18c2

Please sign in to comment.
You can’t perform that action at this time.