6 require_once
'Services/Environment/classes/class.ilRuntime.php';
22 require_once(
"Services/Exceptions/classes/class.ilDelegatingHandler.php");
23 require_once(
"Services/Exceptions/classes/class.ilPlainTextHandler.php");
24 require_once(
"Services/Exceptions/classes/class.ilTestingHandler.php");
73 parent::__construct();
76 $this->DEBUG_ENV =
true;
81 $this->error_obj =
false;
86 restore_error_handler();
87 set_error_handler(array($this,
"handlePreWhoops"));
100 if (self::$whoops_handlers_registered) {
110 if ($ilRuntime->shouldLogErrors()) {
111 $this->whoops->pushHandler($this->loggingHandler());
114 $this->whoops->register();
116 self::$whoops_handlers_registered =
true;
142 return $this->error_obj;
156 if ($a_error_obj->getCode() == null) {
160 $this->error_obj = &$a_error_obj;
162 if (
$_SESSION[
"failure"] && substr($a_error_obj->getMessage(), 0, 22) !=
"Cannot find this block") {
163 $m =
"Fatal Error: Called raise error two times.<br>" .
164 "First error: " .
$_SESSION[
"failure"] .
'<br>' .
165 "Last Error:" . $a_error_obj->getMessage();
168 #$log->writeWarning($m); 169 #$log->logError($a_error_obj->getCode(), $m); 174 if (substr($a_error_obj->getMessage(), 0, 22) ==
"Cannot find this block") {
176 echo "<b>DEVMODE</b><br><br>";
177 echo "<b>Template Block not found.</b><br>";
178 echo "You used a template block in your code that is not available.<br>";
179 echo "Native Messge: <b>" . $a_error_obj->getMessage() .
"</b><br>";
180 if (is_array($a_error_obj->backtrace)) {
181 echo "Backtrace:<br>";
182 foreach ($a_error_obj->backtrace as $b) {
183 if ($b[
"function"] ==
"setCurrentBlock" &&
184 basename($b[
"file"]) !=
"class.ilTemplate.php") {
187 echo "File: " . $b[
"file"] .
", ";
188 echo "Line: " . $b[
"line"] .
", ";
189 echo $b[
"function"] .
"()<br>";
190 if ($b[
"function"] ==
"setCurrentBlock" &&
191 basename($b[
"file"]) !=
"class.ilTemplate.php") {
201 if (is_object($log)
and $log->enabled ==
true) {
202 $log->write($a_error_obj->getMessage());
203 #$log->logError($a_error_obj->getCode(),$a_error_obj->getMessage()); 208 trigger_error(stripslashes($a_error_obj->getMessage()), E_USER_ERROR);
213 if ($this->DEBUG_ENV) {
214 $message = $a_error_obj->getMessage();
221 if (!defined(
"ILIAS_MODULE")) {
229 $_SESSION[
"failure"] = $a_error_obj->getMessage();
234 $dirname = dirname(
$_SERVER[
"PHP_SELF"]);
235 $ilurl = parse_url(ILIAS_HTTP_PATH);
236 $subdir = substr(strstr($dirname, $ilurl[
"path"]), strlen($ilurl[
"path"]));
240 $num_subdirs = substr_count($subdir,
"/");
242 for (
$i = 1;
$i <= $num_subdirs;
$i++) {
271 $this->message = $a_message;
276 $this->message .=
"<br /> ";
278 $this->message .= $a_message;
296 $ilLog->write(
'PHP errror: ' . $errstr .
'. FATAL error on line ' . $errline .
' in file ' . $errfile);
301 $ilLog->write(
'PHP warning: [' . $errno .
'] ' . $errstr .
' on line ' . $errline .
' in file ' . $errfile);
332 return defined(
"DEVMODE") && (int) DEVMODE === 1;
345 require_once(
"Services/Logging/classes/error/class.ilLoggingErrorSettings.php");
346 require_once(
"Services/Logging/classes/error/class.ilLoggingErrorFileStorage.php");
347 require_once(
"Services/Utilities/classes/class.ilUtil.php");
349 $session_id = substr(session_id(), 0, 5);
350 $random = new \ilRandom();
351 $err_num = $random->int(1, 9999);
352 $file_name = $session_id .
"_" . $err_num;
355 if (!empty($logger->folder())) {
362 $lng->loadLanguageModule(
'logging');
363 $message = sprintf($lng->txt(
"log_error_message"), $file_name);
365 if ($logger->mail()) {
366 $message .=
" " . sprintf($lng->txt(
"log_error_message_send_mail"), $logger->mail(), $file_name, $logger->mail());
369 $message =
'Sorry, an error occured. A logfile has been created which can be identified via the code "' . $file_name .
'"';
371 if ($logger->mail()) {
372 $message .=
' ' .
'Please send a mail to <a href="mailto:' . $logger->mail() .
'?subject=code: ' . $file_name .
'">' . $logger->mail() .
'</a>';
389 switch (ERROR_HANDLER) {
398 $ilLog->write(
"Unknown or undefined error handler '" . ERROR_HANDLER .
"'. " 399 .
"Falling back to PrettyPageHandler.");
409 protected function loggingHandler()
419 if (is_object($ilLog)) {
420 $message = $exception->getMessage() .
' in ' . $exception->getFile() .
":" . $exception->getLine();
421 $message .= $exception->getTraceAsString();
422 $ilLog->error($exception->getCode() .
' ' .
$message);
434 if ($level & error_reporting()) {
438 if (version_compare(PHP_VERSION,
'7.0.0',
'<')) {
439 if ($level == E_STRICT) {
440 if (!stristr(
$message,
"should be compatible") &&
441 !stristr(
$message,
"should not be called statically") &&
442 !stristr(
$message,
"should not be abstract")) {
451 if ($level >= E_USER_NOTICE) {
453 $severity = Whoops\Util\Misc::TranslateErrorCode($level);
454 $ilLog->write(
"\n\n" . $severity .
" - " .
$message .
"\n" . $file .
" - line " . $line .
"\n");
462 return $this->whoops->handleError($level,
$message, $file, $line);
isDevmodeActive()
Is the DEVMODE switched on?
getWhoops()
Get an instance of Whoops/Run.
static $whoops_handlers_registered
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
__construct()
Constructor public.
appendMessage($a_message)
Saves error informations into file.
Error Handling & global info handling uses PEAR error class.
defaultHandler()
Get a default error handler.
getIlRuntime()
Get ilRuntime.
catch(Exception $e) $message
getHandler()
Get a handler for an error or exception.
errorHandler($a_error_obj)
defines what has to happen in case of error private
static _ilErrorWriter($errno, $errstr, $errfile, $errline)
This is used in Soap calls to write PHP error in ILIAS Logfile Not used yet!!!
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
handlePreWhoops($level, $message, $file, $line)
initWhoopsHandlers()
Initialize Error and Exception Handlers.
devmodeHandler()
Get the handler to be used in DEVMODE.
A Whoops error handler for testing.
Wrapper for Closures passed as handlers.
static redirect($a_script)