From b367c951b990b38677e67f1a1756cd4d1eaee50b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Apr 2013 09:45:43 +0400 Subject: make logging configurable; add logging to syslog --- classes/logger.php | 39 ++++++++++++++++++++++-- classes/logger/sql.php | 3 -- classes/logger/syslog.php | 31 ++++++++++++++++++++ classes/pref/system.php | 75 ++++++++++++++++++++++++++--------------------- 4 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 classes/logger/syslog.php (limited to 'classes') diff --git a/classes/logger.php b/classes/logger.php index 3c501eb92..4a9c1df82 100644 --- a/classes/logger.php +++ b/classes/logger.php @@ -1,5 +1,7 @@ 'E_ERROR', @@ -20,11 +22,44 @@ class Logger { 32767 => 'E_ALL'); function log_error($errno, $errstr, $file, $line, $context) { - return false; + if ($errno == E_NOTICE) return false; + + if ($this->adapter) + return $this->adapter->log_error($errno, $errstr, $file, $line, $context); + else + return false; } function log($string) { - return false; + if ($this->adapter) + return $this->adapter->log($string); + else + return false; + } + + private function __clone() { + // + } + + function __construct() { + switch (LOG_DESTINATION) { + case "sql": + $this->adapter = new Logger_SQL(); + break; + case "syslog": + $this->adapter = new Logger_Syslog(); + break; + default: + $this->adapter = false; + } } + + public static function get() { + if (self::$instance == null) + self::$instance = new self(); + + return self::$instance; + } + } ?> diff --git a/classes/logger/sql.php b/classes/logger/sql.php index 50e5de9a6..c0f8b4598 100644 --- a/classes/logger/sql.php +++ b/classes/logger/sql.php @@ -2,9 +2,6 @@ class Logger_SQL { function log_error($errno, $errstr, $file, $line, $context) { - - if ($errno == E_NOTICE) return false; - if (Db::get() && get_schema_version() > 117) { $errno = Db::get()->escape_string($errno); diff --git a/classes/logger/syslog.php b/classes/logger/syslog.php new file mode 100644 index 000000000..b8b5260a0 --- /dev/null +++ b/classes/logger/syslog.php @@ -0,0 +1,31 @@ + diff --git a/classes/pref/system.php b/classes/pref/system.php index 725c337dc..d2b6cd746 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -24,46 +24,53 @@ class Pref_System extends Handler_Protected { print "
"; print "
"; - $result = $this->dbh->query("SELECT errno, errstr, filename, lineno, - created_at, login FROM ttrss_error_log - LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) - ORDER BY ttrss_error_log.id DESC - LIMIT 100"); - - print " "; - - print "

"; - - print " - - - - - - "; - - while ($line = $this->dbh->fetch_assoc($result)) { - print ""; - - foreach ($line as $k => $v) { - $line[$k] = htmlspecialchars($v); + if (LOG_DESTINATION == "sql") { + + $result = $this->dbh->query("SELECT errno, errstr, filename, lineno, + created_at, login FROM ttrss_error_log + LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id) + ORDER BY ttrss_error_log.id DESC + LIMIT 100"); + + print " "; + + print "

".__("Error")."".__("Filename")."".__("Message")."".__("User")."".__("Date")."
"; + + print " + + + + + + "; + + while ($line = $this->dbh->fetch_assoc($result)) { + print ""; + + foreach ($line as $k => $v) { + $line[$k] = htmlspecialchars($v); + } + + print ""; + print ""; + print ""; + print ""; + + print ""; + + print ""; } - print ""; - print ""; - print ""; - print ""; + print "
".__("Error")."".__("Filename")."".__("Message")."".__("User")."".__("Date")."
" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")" . $line["filename"] . ":" . $line["lineno"] . "" . $line["errstr"] . "" . + make_local_datetime( + $line["created_at"], false) . "
" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")" . $line["filename"] . ":" . $line["lineno"] . "" . $line["errstr"] . "
"; + } else { - print "" . - make_local_datetime( - $line["created_at"], false) . ""; + print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging."); - print ""; } - print ""; - print "

"; PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, -- cgit v1.2.3-54-g00ecf