mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-14 01:05:56 +00:00
debug logging system rework:
* support various logging levels per-message * remove hacks like debug_suppress, DAEMON_EXTENDED_DEBUG, etc * _debug() is kept as a compatibility shim for plugins
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
$fetch_last_error_content = false; // curl only for the time being
|
||||
$fetch_effective_url = false;
|
||||
$fetch_curl_used = false;
|
||||
$suppress_debugging = false;
|
||||
|
||||
libxml_disable_entity_loader(true);
|
||||
|
||||
@@ -156,67 +155,11 @@
|
||||
|
||||
$schema_version = false;
|
||||
|
||||
function _debug_suppress($suppress) {
|
||||
global $suppress_debugging;
|
||||
|
||||
$suppress_debugging = $suppress;
|
||||
// TODO: compat wrapper, remove at some point
|
||||
function _debug($msg) {
|
||||
Debug::log($msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a timestamped debug message.
|
||||
*
|
||||
* @param string $msg The debug message.
|
||||
* @return void
|
||||
*/
|
||||
function _debug($msg, $show = true) {
|
||||
global $suppress_debugging;
|
||||
|
||||
//echo "[$suppress_debugging] $msg $show\n";
|
||||
|
||||
if ($suppress_debugging) return false;
|
||||
|
||||
$ts = strftime("%H:%M:%S", time());
|
||||
if (function_exists('posix_getpid')) {
|
||||
$ts = "$ts/" . posix_getpid();
|
||||
}
|
||||
|
||||
if ($show && !(defined('QUIET') && QUIET)) {
|
||||
print "[$ts] $msg\n";
|
||||
}
|
||||
|
||||
if (defined('LOGFILE')) {
|
||||
$fp = fopen(LOGFILE, 'a+');
|
||||
|
||||
if ($fp) {
|
||||
$locked = false;
|
||||
|
||||
if (function_exists("flock")) {
|
||||
$tries = 0;
|
||||
|
||||
// try to lock logfile for writing
|
||||
while ($tries < 5 && !$locked = flock($fp, LOCK_EX | LOCK_NB)) {
|
||||
sleep(1);
|
||||
++$tries;
|
||||
}
|
||||
|
||||
if (!$locked) {
|
||||
fclose($fp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
fputs($fp, "[$ts] $msg\n");
|
||||
|
||||
if (function_exists("flock")) {
|
||||
flock($fp, LOCK_UN);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
} // function _debug
|
||||
|
||||
/**
|
||||
* Purge a feed old posts.
|
||||
*
|
||||
@@ -227,7 +170,7 @@
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function purge_feed($feed_id, $purge_interval, $debug = false) {
|
||||
function purge_feed($feed_id, $purge_interval) {
|
||||
|
||||
if (!$purge_interval) $purge_interval = feed_purge_interval($feed_id);
|
||||
|
||||
@@ -292,9 +235,7 @@
|
||||
|
||||
CCache::update($feed_id, $owner_uid);
|
||||
|
||||
if ($debug) {
|
||||
_debug("Purged feed $feed_id ($purge_interval): deleted $rows articles");
|
||||
}
|
||||
Debug::log("Purged feed $feed_id ($purge_interval): deleted $rows articles");
|
||||
|
||||
return $rows;
|
||||
} // function purge_feed
|
||||
@@ -421,7 +362,7 @@
|
||||
// holy shit closures in php
|
||||
// download & upload are *expected* sizes respectively, could be zero
|
||||
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($curl_handle, $download_size, $downloaded, $upload_size, $uploaded) use( &$max_size) {
|
||||
//_debug("[curl progressfunction] $downloaded $max_size");
|
||||
Debug::log("[curl progressfunction] $downloaded $max_size", Debug::$LOG_EXTENDED);
|
||||
|
||||
return ($downloaded > $max_size) ? 1 : 0; // if max size is set, abort when exceeding it
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user