From 475d7628723b033e90d2b70bd084c42941f795d6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 3 Dec 2015 16:15:28 +0300 Subject: [PATCH] logger: record last query before logged error --- classes/db/mysqli.php | 4 ++++ classes/db/pgsql.php | 4 ++++ include/errorhandler.php | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/classes/db/mysqli.php b/classes/db/mysqli.php index c685b75a..eef500f7 100644 --- a/classes/db/mysqli.php +++ b/classes/db/mysqli.php @@ -24,6 +24,10 @@ class Db_Mysqli implements IDb { } function query($query, $die_on_error = true) { + global $last_query; + + if (strpos($query, "ttrss_error_log") === FALSE) $last_query = $query; + $result = @mysqli_query($this->link, $query); if (!$result) { $error = @mysqli_error($this->link); diff --git a/classes/db/pgsql.php b/classes/db/pgsql.php index 6b772d9e..7bdcb7e9 100644 --- a/classes/db/pgsql.php +++ b/classes/db/pgsql.php @@ -35,6 +35,10 @@ class Db_Pgsql implements IDb { } function query($query, $die_on_error = true) { + global $last_query; + + if (strpos($query, "ttrss_error_log") === FALSE) $last_query = $query; + $result = @pg_query($this->link, $query); if (!$result) { diff --git a/include/errorhandler.php b/include/errorhandler.php index 52431c2d..21cc9a94 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -1,17 +1,21 @@ log_error($errno, $errstr, $file, $line, $context); } function ttrss_fatal_handler() { global $logger; + global $last_query; $error = error_get_last(); @@ -27,6 +31,8 @@ function ttrss_fatal_handler() { $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); + if ($last_query) $errstr .= " [Last query: $last_query]"; + if (class_exists("Logger")) return Logger::get()->log_error($errno, $errstr, $file, $line, $context); } -- 2.39.5