]>
git.wh0rd.org - tt-rss.git/blob - include/errorhandler.php
2 function format_backtrace($trace) {
6 if (is_array($trace)) {
7 foreach ($trace as $e) {
8 if (isset($e["file"]) && isset($e["line"])) {
11 if (is_array($e["args"])) {
12 foreach ($e["args"] as $a) {
14 array_push($fmt_args, $a);
16 array_push($fmt_args, "[" . get_class($a) . "]");
21 $filename = str_replace(dirname(__DIR__
) . "/", "", $e["file"]);
23 $rv .= sprintf("%d. %s(%s): %s(%s)\n",
24 $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args));
34 function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
37 if (error_reporting() == 0 ||
!$errno) return false;
39 $file = substr(str_replace(dirname(dirname(__FILE__
)), "", $file), 1);
41 $context = format_backtrace(debug_backtrace());
42 $errstr = truncate_middle($errstr, 16384, " (...) ");
44 if (class_exists("Logger"))
45 return Logger
::get()->log_error($errno, $errstr, $file, $line, $context);
48 function ttrss_fatal_handler() {
52 $error = error_get_last();
54 if ($error !== NULL) {
55 $errno = $error["type"];
56 $file = $error["file"];
57 $line = $error["line"];
58 $errstr = $error["message"];
60 if (!$errno) return false;
62 $context = format_backtrace(debug_backtrace());
64 $file = substr(str_replace(dirname(dirname(__FILE__
)), "", $file), 1);
66 if ($last_query) $errstr .= " [Last query: $last_query]";
68 if (class_exists("Logger"))
69 return Logger
::get()->log_error($errno, $errstr, $file, $line, $context);
75 register_shutdown_function('ttrss_fatal_handler');
76 set_error_handler('ttrss_error_handler');