2 namespace TYPO3\CMS\Core\Error;
47 $excludedErrors = E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_ERROR;
49 $errorHandlerErrors = $errorHandlerErrors & ~$excludedErrors;
50 set_error_handler(array($this,
'handleError'), $errorHandlerErrors);
86 public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine)
89 if (error_reporting() === 0) {
93 E_WARNING =>
'Warning',
95 E_USER_ERROR =>
'User Error',
96 E_USER_WARNING =>
'User Warning',
97 E_USER_NOTICE =>
'User Notice',
98 E_STRICT =>
'Runtime Notice',
99 E_RECOVERABLE_ERROR =>
'Catchable Fatal Error',
100 E_DEPRECATED =>
'Runtime Deprecation Notice'
102 $message =
'PHP ' . $errorLevels[$errorLevel] .
': ' . $errorMessage .
' in ' . $errorFile .
' line ' . $errorLine;
103 if ($errorLevel & $this->exceptionalErrors) {
106 if (!class_exists(
'stdClass',
false)) {
107 $message =
'PHP ' . $errorLevels[$errorLevel] .
': ' . $errorMessage .
' in ' . basename($errorFile) .
108 'line ' . $errorLine;
111 throw new Exception($message, 1);
113 switch ($errorLevel) {
115 case E_RECOVERABLE_ERROR:
125 $logTitle =
'Core: Error handler (' . TYPO3_MODE .
')';
126 $message = $logTitle .
': ' . $message;
129 if ($errorLevel &
$GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'syslogErrorReporting']) {
130 GeneralUtility::sysLog($message,
'core', $severity + 1);
134 if (TYPO3_ERROR_DLOG) {
138 if (is_object($GLOBALS[
'TT'])) {
139 $GLOBALS[
'TT']->setTSlogMessage($message, $severity + 1);
142 if ($errorLevel & $GLOBALS[
'TYPO3_CONF_VARS'][
'SYS'][
'belogErrorReporting']) {
146 $this->
writeLog($message, $severity);
147 }
catch (\Exception $e) {
150 if ($severity === 2) {
154 if ($this->debugMode) {
157 \TYPO3\CMS\Core\Messaging\FlashMessage::class,
159 'PHP ' . $errorLevels[$errorLevel],
165 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
166 $defaultFlashMessageQueue->enqueue($flashMessage);
181 protected function writeLog($logMessage, $severity)
183 if (is_object($GLOBALS[
'TYPO3_DB']) && $GLOBALS[
'TYPO3_DB']->isConnected()) {
186 if (is_object($GLOBALS[
'BE_USER'])) {
187 if (isset($GLOBALS[
'BE_USER']->user[
'uid'])) {
188 $userId = $GLOBALS[
'BE_USER']->user[
'uid'];
190 if (isset($GLOBALS[
'BE_USER']->workspace)) {
191 $workspace = $GLOBALS[
'BE_USER']->workspace;
194 $fields_values = array(
198 'error' => $severity,
200 'details' => str_replace(
'%',
'%%', $logMessage),
202 'tstamp' => $GLOBALS[
'EXEC_TIME'],
203 'workspace' => $workspace
205 $GLOBALS[
'TYPO3_DB']->exec_INSERTquery(
'sys_log', $fields_values);