summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-04-16 19:41:31 +0400
committerAndrew Dolgov <[email protected]>2013-04-16 19:41:31 +0400
commit889a5f9f195309df5842f142986b3166212d8a58 (patch)
treeddefb4fe997bb9625856e56196e4b9e84592e742 /include
parent4f032700dbfbbfa35798e05497c8a868eb73476f (diff)
experimental SQL-based error logger
Diffstat (limited to 'include')
-rw-r--r--include/errorhandler.php50
-rw-r--r--include/functions.php15
-rw-r--r--include/sessions.php1
3 files changed, 63 insertions, 3 deletions
diff --git a/include/errorhandler.php b/include/errorhandler.php
new file mode 100644
index 000000000..13eed0e30
--- /dev/null
+++ b/include/errorhandler.php
@@ -0,0 +1,50 @@
+<?php
+// TODO: make configurable
+require_once "classes/logger.php";
+require_once "classes/logger/sql.php";
+
+function ttrss_error_handler($errno, $errstr, $file, $line, $context) {
+ global $logger;
+
+ if (!$logger) $logger = new Logger_SQL();
+
+ $errfile = str_replace(dirname(dirname(__FILE__)), "", $errfile);
+
+ if ($logger) {
+ return $logger->log_error($errno, $errstr, $file, $line, $context);
+ }
+
+ return false;
+}
+
+function ttrss_fatal_handler() {
+ global $logger;
+
+ $file = "UNKNOWN FILE";
+ $errstr = "UNKNOWN";
+ $errno = E_CORE_ERROR;
+ $line = -1;
+
+ $error = error_get_last();
+
+ if ($error !== NULL) {
+ $errno = $error["type"];
+ $file = $error["file"];
+ $line = $error["line"];
+ $errstr = $error["message"];
+
+ $context = debug_backtrace();
+
+ $file = str_replace(dirname(dirname(__FILE__)) . "/", "", $file);
+
+ if (!$logger) $logger = new Logger_SQL();
+
+ if ($logger) {
+ $logger->log_error($errno, $errstr, $file, $line, $context);
+ }
+ }
+}
+
+register_shutdown_function('ttrss_fatal_handler');
+set_error_handler('ttrss_error_handler');
+?>
diff --git a/include/functions.php b/include/functions.php
index 659950be0..621357ea6 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,6 +1,6 @@
<?php
define('EXPECTED_CONFIG_VERSION', 26);
- define('SCHEMA_VERSION', 117);
+ define('SCHEMA_VERSION', 118);
define('LABEL_BASE_INDEX', -1024);
define('PLUGIN_FEED_BASE_INDEX', -128);
@@ -3369,9 +3369,8 @@
return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
}
- function init_connection($link) {
+ function init_connection_only($link) {
if ($link) {
-
if (DB_TYPE == "pgsql") {
pg_query($link, "set client_encoding = 'UTF-8'");
pg_set_client_encoding("UNICODE");
@@ -3385,6 +3384,16 @@
}
}
+ return true;
+ }
+
+ return false;
+ }
+
+ function init_connection($link) {
+ if ($link) {
+ init_connection_only($link);
+
global $pluginhost;
$pluginhost = new PluginHost($link);
diff --git a/include/sessions.php b/include/sessions.php
index 402e8b8de..bc8b7cff1 100644
--- a/include/sessions.php
+++ b/include/sessions.php
@@ -3,6 +3,7 @@
require_once "config.php";
require_once "db.php";
+ require_once "errorhandler.php";
require_once "lib/accept-to-gettext.php";
require_once "lib/gettext/gettext.inc";
require_once "version.php";