From: Andrew Dolgov Date: Fri, 19 Apr 2013 05:45:43 +0000 (+0400) Subject: make logging configurable; add logging to syslog X-Git-Tag: 1.7.9~25^2~129 X-Git-Url: https://git.wh0rd.org/?p=tt-rss.git;a=commitdiff_plain;h=b367c951b990b38677e67f1a1756cd4d1eaee50b make logging configurable; add logging to syslog --- diff --git a/classes/logger.php b/classes/logger.php index 3c501eb9..4a9c1df8 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 50e5de9a..c0f8b459 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 00000000..b8b5260a --- /dev/null +++ b/classes/logger/syslog.php @@ -0,0 +1,31 @@ + diff --git a/classes/pref/system.php b/classes/pref/system.php index 725c337d..d2b6cd74 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, diff --git a/config.php-dist b/config.php-dist index 7cb9d939..1c356a9a 100644 --- a/config.php-dist +++ b/config.php-dist @@ -192,6 +192,12 @@ // authentication plugin here (auth_*). // Users may enable other user plugins from Preferences/Plugins but may not // disable plugins specified in this list. + + define('LOG_DESTINATION', 'sql'); + // Log destination to use. Possible values: sql (uses internal logging + // you can read in Preferences -> System), syslog - logs to system log. + // Setting this to blank uses PHP logging (usually to http server + // error.log). define('CONFIG_VERSION', 26); // Expected config version. Please update this option in config.php diff --git a/include/errorhandler.php b/include/errorhandler.php index 2c8d35f8..9acef235 100644 --- a/include/errorhandler.php +++ b/include/errorhandler.php @@ -1,22 +1,12 @@ log_error($errno, $errstr, $file, $line, $context); - } - - return false; + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); } function ttrss_fatal_handler() { @@ -36,14 +26,7 @@ function ttrss_fatal_handler() { $file = substr(str_replace(dirname(dirname(__FILE__)), "", $file), 1); - if (!$logger) $logger = new Logger_SQL(); - - if ($logger) { - if ($logger->log_error($errno, $errstr, $file, $line, $context)) { - return true; - } - } - return false; + return Logger::get()->log_error($errno, $errstr, $file, $line, $context); } return false; diff --git a/include/sanity_config.php b/include/sanity_config.php index d5cfd2d7..7d8afe10 100644 --- a/include/sanity_config.php +++ b/include/sanity_config.php @@ -1,3 +1,3 @@ - +$requred_defines = array( 'DB_TYPE', 'DB_HOST', 'DB_USER', 'DB_NAME', 'DB_PASS', 'MYSQL_CHARSET', 'SELF_URL_PATH', 'FEED_CRYPT_KEY', 'SINGLE_USER_MODE', 'SIMPLE_UPDATE_MODE', 'PHP_EXECUTABLE', 'LOCK_DIRECTORY', 'CACHE_DIR', 'ICONS_DIR', 'ICONS_URL', 'AUTH_AUTO_CREATE', 'AUTH_AUTO_LOGIN', 'FORCE_ARTICLE_PURGE', 'PUBSUBHUBBUB_HUB', 'PUBSUBHUBBUB_ENABLED', 'SPHINX_ENABLED', 'SPHINX_SERVER', 'SPHINX_INDEX', 'ENABLE_REGISTRATION', 'REG_NOTIFY_ADDRESS', 'REG_MAX_USERS', 'SESSION_COOKIE_LIFETIME', 'SESSION_CHECK_ADDRESS', 'SMTP_FROM_NAME', 'SMTP_FROM_ADDRESS', 'DIGEST_SUBJECT', 'SMTP_SERVER', 'SMTP_LOGIN', 'SMTP_PASSWORD', 'CHECK_FOR_NEW_VERSION', 'ENABLE_GZIP_OUTPUT', 'PLUGINS', 'LOG_DESTINATION', 'CONFIG_VERSION'); ?>