]>
Commit | Line | Data |
---|---|---|
889a5f9f | 1 | <?php |
b8619f8d AD |
2 | function format_backtrace($trace) { |
3 | $rv = ""; | |
4 | $idx = 1; | |
5 | ||
6 | if (is_array($trace)) { | |
7 | foreach ($trace as $e) { | |
8 | if (isset($e["file"]) && isset($e["line"])) { | |
9 | $fmt_args = []; | |
10 | ||
11 | if (is_array($e["args"])) { | |
12 | foreach ($e["args"] as $a) { | |
13 | if (!is_object($a)) { | |
14 | array_push($fmt_args, $a); | |
15 | } else { | |
16 | array_push($fmt_args, "[" . get_class($a) . "]"); | |
17 | } | |
18 | } | |
19 | } | |
20 | ||
21 | $filename = str_replace(dirname(__DIR__) . "/", "", $e["file"]); | |
22 | ||
23 | $rv .= sprintf("%d. %s(%s): %s(%s)\n", | |
24 | $idx, $filename, $e["line"], $e["function"], implode(", ", $fmt_args)); | |
25 | ||
26 | $idx++; | |
27 | } | |
28 | } | |
29 | } | |
30 | ||
31 | return $rv; | |
32 | } | |
33 | ||
889a5f9f AD |
34 | function ttrss_error_handler($errno, $errstr, $file, $line, $context) { |
35 | global $logger; | |
475d7628 | 36 | global $last_query; |
889a5f9f | 37 | |
eefaa2df | 38 | if (error_reporting() == 0 || !$errno) return false; |
7a51032c | 39 | |
4e53956a | 40 | $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
889a5f9f | 41 | |
475d7628 | 42 | if ($last_query) $errstr .= " [Last query: $last_query]"; |
b8619f8d | 43 | $context = format_backtrace(debug_backtrace()); |
475d7628 | 44 | |
15d52d51 AD |
45 | if (class_exists("Logger")) |
46 | return Logger::get()->log_error($errno, $errstr, $file, $line, $context); | |
889a5f9f AD |
47 | } |
48 | ||
49 | function ttrss_fatal_handler() { | |
50 | global $logger; | |
475d7628 | 51 | global $last_query; |
889a5f9f | 52 | |
889a5f9f AD |
53 | $error = error_get_last(); |
54 | ||
55 | if ($error !== NULL) { | |
77be1217 | 56 | $errno = $error["type"]; |
889a5f9f AD |
57 | $file = $error["file"]; |
58 | $line = $error["line"]; | |
59 | $errstr = $error["message"]; | |
60 | ||
eefaa2df AD |
61 | if (!$errno) return false; |
62 | ||
b8619f8d | 63 | $context = format_backtrace(debug_backtrace()); |
889a5f9f | 64 | |
4e53956a | 65 | $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); |
889a5f9f | 66 | |
475d7628 AD |
67 | if ($last_query) $errstr .= " [Last query: $last_query]"; |
68 | ||
15d52d51 AD |
69 | if (class_exists("Logger")) |
70 | return Logger::get()->log_error($errno, $errstr, $file, $line, $context); | |
889a5f9f | 71 | } |
aca75cb5 AD |
72 | |
73 | return false; | |
889a5f9f AD |
74 | } |
75 | ||
7329ab2d AD |
76 | register_shutdown_function('ttrss_fatal_handler'); |
77 | set_error_handler('ttrss_error_handler'); | |
889a5f9f | 78 | ?> |