]> git.wh0rd.org Git - tt-rss.git/blob - classes/logger.php
732f1fd5d087d802b5cfed19b4afb195764288c3
[tt-rss.git] / classes / logger.php
1 <?php
2 class Logger {
3         private static $instance;
4         private $adapter;
5
6         public static $errornames = array(
7                 1                       => 'E_ERROR',
8                 2                       => 'E_WARNING',
9                 4                       => 'E_PARSE',
10                 8                       => 'E_NOTICE',
11                 16                      => 'E_CORE_ERROR',
12                 32                      => 'E_CORE_WARNING',
13                 64                      => 'E_COMPILE_ERROR',
14                 128             => 'E_COMPILE_WARNING',
15                 256             => 'E_USER_ERROR',
16                 512             => 'E_USER_WARNING',
17                 1024            => 'E_USER_NOTICE',
18                 2048            => 'E_STRICT',
19                 4096            => 'E_RECOVERABLE_ERROR',
20                 8192            => 'E_DEPRECATED',
21                 16384           => 'E_USER_DEPRECATED',
22                 32767           => 'E_ALL');
23
24         function log_error($errno, $errstr, $file, $line, $context) {
25                 if ($errno == E_NOTICE) return false;
26
27                 if ($this->adapter)
28                         return $this->adapter->log_error($errno, $errstr, $file, $line, $context);
29                 else
30                         return false;
31         }
32
33         function log($string, $context = "") {
34                 if ($this->adapter)
35                         return $this->adapter->log_error(E_USER_NOTICE, $string, '', 0, $context);
36                 else
37                         return false;
38         }
39
40         private function __clone() {
41                 //
42         }
43
44         function __construct() {
45                 switch (LOG_DESTINATION) {
46                 case "sql":
47                         $this->adapter = new Logger_SQL();
48                         break;
49                 case "syslog":
50                         $this->adapter = new Logger_Syslog();
51                         break;
52                 case "stdout":
53                         $this->adapter = new Logger_Stdout();
54                         break;
55                 default:
56                         $this->adapter = false;
57                 }
58         }
59
60         public static function get() {
61                 if (self::$instance == null)
62                         self::$instance = new self();
63
64                 return self::$instance;
65         }
66
67 }