diff --git a/classes/exception/PrestaShopException.php b/classes/exception/PrestaShopException.php
index c0920313c..ce369186a 100644
--- a/classes/exception/PrestaShopException.php
+++ b/classes/exception/PrestaShopException.php
@@ -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
';
echo '
';
echo '
['.get_class($this).']
';
- printf(
- '
%s
at line %d in file %s
',
- $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 '';
}
+
+ /**
+ * 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 = '
%s
at line %d in file %s
';
+ if (!$html)
+ $format = strip_tags(str_replace('
', ' ', $format));
+
+ return sprintf(
+ $format,
+ $this->getMessage(),
+ $this->getLine(),
+ ltrim(str_replace(array(_PS_ROOT_DIR_, '\\'), array('', '/'), $this->getFile()), '/')
+ );
+ }
+
}