[*] Core: Log the exceptions in a file #PSCFV-6334

This commit is contained in:
Rémi Gaillard
2012-12-28 16:12:28 +01:00
parent 33f09fb92f
commit 5e367744b6
+34 -8
View File
@@ -34,6 +34,7 @@ class PrestaShopExceptionCore extends Exception
*/
public function displayMessage()
{
header('HTTP/1.1 500 Internal Server Error');
if (_PS_MODE_DEV_ || defined('_PS_ADMIN_DIR_'))
{
// Display error message
@@ -50,12 +51,7 @@ class PrestaShopExceptionCore extends Exception
</style>';
echo '<div id="psException">';
echo '<h2>['.get_class($this).']</h2>';
printf(
'<p><b>%s</b><br /><i>at line </i><b>%d</b><i> in file </i><b>%s</b></p>',
$this->getMessage(),
$this->getLine(),
ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/')
);
echo $this->getExentedMessage();
$this->displayFileDebug($this->getFile(), $this->getLine());
@@ -85,11 +81,12 @@ class PrestaShopExceptionCore extends Exception
}
else
{
// If not in mode dev, launch a http 500 error
header('HTTP/1.1 500 Internal Server Error');
// If not in mode dev, display an error page
if (file_exists(_PS_ROOT_DIR_.'/error500.html'))
echo file_get_contents(_PS_ROOT_DIR_.'/error500.html');
}
// Log the error in the disk
$this->logError();
exit;
}
@@ -140,4 +137,33 @@ class PrestaShopExceptionCore extends Exception
}
echo '</pre>';
}
/**
* Log the error on the disk
*/
protected function logError()
{
$logger = new FileLogger();
$logger->setFilename(_PS_ROOT_DIR_.'/log/'.date('Ymd').'_exception.log');
$logger->logError($this->getExentedMessage(false));
}
/**
* Return the content of the Exception
* @return string content of the exception
*/
protected function getExentedMessage($html = true)
{
$format = '<p><b>%s</b><br /><i>at line </i><b>%d</b><i> in file </i><b>%s</b></p>';
if (!$html)
$format = strip_tags(str_replace('<br />', ' ', $format));
return sprintf(
$format,
$this->getMessage(),
$this->getLine(),
ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/')
);
}
}