]> git.wh0rd.org - tt-rss.git/blob - classes/logger/sql.php
experimental SQL-based error logger
[tt-rss.git] / classes / logger / sql.php
1 <?php
2 class Logger_SQL {
3
4 private $link;
5
6 function __construct() {
7 $this->link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
8 }
9
10 function log_error($errno, $errstr, $file, $line, $context) {
11
12 if ($errno == E_NOTICE) return false;
13
14 if ($this->link) {
15 $errno = db_escape_string($this->link, $errno);
16 $errstr = db_escape_string($this->link, $errstr);
17 $file = db_escape_string($this->link, $file);
18 $line = db_escape_string($this->link, $line);
19 $context = db_escape_string($this->link, json_encode($context));
20
21 $owner_uid = $_SESSION["uid"] ? $_SESSION["uid"] : "NULL";
22
23 $result = db_query($this->link,
24 "INSERT INTO ttrss_error_log
25 (errno, errstr, filename, lineno, context, owner_uid, created_at) VALUES
26 ($errno, '$errstr', '$file', '$line', '$context', $owner_uid, NOW())");
27
28 return db_affected_rows($this->link, $result) != 0;
29
30 }
31 return false;
32 }
33
34 }
35 ?>