experimental SQL-based error logger
parent
4f032700db
commit
889a5f9f19
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
class Logger {
|
||||||
|
|
||||||
|
protected $errornames = array(
|
||||||
|
2 => 'E_WARNING',
|
||||||
|
8 => 'E_NOTICE',
|
||||||
|
256 => 'E_USER_ERROR',
|
||||||
|
512 => 'E_USER_WARNING',
|
||||||
|
1024 => 'E_USER_NOTICE',
|
||||||
|
2048 => 'E_STRICT',
|
||||||
|
4096 => 'E_RECOVERABLE_ERROR',
|
||||||
|
8192 => 'E_DEPRECATED',
|
||||||
|
16384 => 'E_USER_DEPRECATED',
|
||||||
|
32767 => 'E_ALL');
|
||||||
|
|
||||||
|
function log_error($errno, $errstr, $file, $line, $context) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function log($string) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
class Logger_SQL {
|
||||||
|
|
||||||
|
private $link;
|
||||||
|
|
||||||
|
function __construct() {
|
||||||
|
$this->link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
function log_error($errno, $errstr, $file, $line, $context) {
|
||||||
|
|
||||||
|
if ($errno == E_NOTICE) return false;
|
||||||
|
|
||||||
|
if ($this->link) {
|
||||||
|
$errno = db_escape_string($this->link, $errno);
|
||||||
|
$errstr = db_escape_string($this->link, $errstr);
|
||||||
|
$file = db_escape_string($this->link, $file);
|
||||||
|
$line = db_escape_string($this->link, $line);
|
||||||
|
$context = db_escape_string($this->link, json_encode($context));
|
||||||
|
|
||||||
|
$owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
|
||||||
|
|
||||||
|
$result = db_query($this->link,
|
||||||
|
"INSERT INTO ttrss_error_log
|
||||||
|
(errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES
|
||||||
|
($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
|
||||||
|
|
||||||
|
return db_affected_rows($this->link, $result) != 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
@ -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');
|
||||||
|
?>
|
@ -0,0 +1,16 @@
|
|||||||
|
begin;
|
||||||
|
|
||||||
|
create table ttrss_error_log(
|
||||||
|
id integer not null auto_increment primary key,
|
||||||
|
owner_uid integer,
|
||||||
|
errno integer not null,
|
||||||
|
errstr text not null,
|
||||||
|
filename text not null,
|
||||||
|
lineno integer not null,
|
||||||
|
context text not null,
|
||||||
|
created_at datetime not null,
|
||||||
|
foreign key (owner_uid) references ttrss_users(id) ON DELETE SET NULL) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
|
||||||
|
|
||||||
|
update ttrss_version set schema_version = 118;
|
||||||
|
|
||||||
|
commit;
|
@ -0,0 +1,15 @@
|
|||||||
|
begin;
|
||||||
|
|
||||||
|
create table ttrss_error_log(
|
||||||
|
id serial not null primary key,
|
||||||
|
owner_uid integer references ttrss_users(id) ON DELETE SET NULL,
|
||||||
|
errno integer not null,
|
||||||
|
errstr text not null,
|
||||||
|
filename text not null,
|
||||||
|
lineno integer not null,
|
||||||
|
context text not null,
|
||||||
|
created_at timestamp not null);
|
||||||
|
|
||||||
|
update ttrss_version set schema_version = 118;
|
||||||
|
|
||||||
|
commit;
|
Loading…
Reference in New Issue