]>
git.wh0rd.org - tt-rss.git/blob - classes/debug.php
3 public static $LOG_NORMAL = 0;
4 public static $LOG_VERBOSE = 1;
5 public static $LOG_EXTENDED = 2;
7 private static $enabled = false;
8 private static $quiet = false;
9 private static $logfile = false;
10 private static $loglevel = 0;
12 public static function set_logfile($logfile) {
13 Debug
::$logfile = $logfile;
16 public static function enabled() {
17 return Debug
::$enabled;
20 public static function set_enabled($enable) {
21 Debug
::$enabled = $enable;
24 public static function set_quiet($quiet) {
25 Debug
::$quiet = $quiet;
28 public static function set_loglevel($level) {
29 Debug
::$loglevel = $level;
32 public static function get_loglevel() {
33 return Debug
::$loglevel;
36 public static function log($message, $level = 0) {
38 if (!Debug
::$enabled || Debug
::$loglevel < $level) return false;
40 $ts = strftime("%H:%M:%S", time());
41 if (function_exists('posix_getpid')) {
42 $ts = "$ts/" . posix_getpid();
45 if (Debug
::$logfile) {
46 $fp = fopen(Debug
::$logfile, 'a+');
51 if (function_exists("flock")) {
54 // try to lock logfile for writing
55 while ($tries < 5 && !$locked = flock($fp, LOCK_EX | LOCK_NB
)) {
62 user_error("Unable to lock debugging log file: " . Debug
::$logfile, E_USER_WARNING
);
67 fputs($fp, "[$ts] $message\n");
69 if (function_exists("flock")) {
79 user_error("Unable to open debugging log file: " . Debug
::$logfile, E_USER_WARNING
);
83 print "[$ts] $message\n";