Issues (1270)

classes/logger.php (1 issue)

Labels
Severity
1
<?php
2
3
class Logger {
4
5
    /**
6
     * @var Logger
7
     */
8
    private static $instance;
9
10
    /**
11
     * @var bool|Logger_SQL|Logger_Syslog
12
     */
13
    private $adapter;
14
15
    public static $errornames = array(
16
        1 => 'E_ERROR',
17
        2 => 'E_WARNING',
18
        4 => 'E_PARSE',
19
        8 => 'E_NOTICE',
20
        16 => 'E_CORE_ERROR',
21
        32 => 'E_CORE_WARNING',
22
        64 => 'E_COMPILE_ERROR',
23
        128 => 'E_COMPILE_WARNING',
24
        256 => 'E_USER_ERROR',
25
        512 => 'E_USER_WARNING',
26
        1024 => 'E_USER_NOTICE',
27
        2048 => 'E_STRICT',
28
        4096 => 'E_RECOVERABLE_ERROR',
29
        8192 => 'E_DEPRECATED',
30
        16384 => 'E_USER_DEPRECATED',
31
        32767 => 'E_ALL');
32
33
    public function log_error($errno, $errstr, $file, $line, $context) {
34
        if ($errno === E_NOTICE) {
35
            return false;
36
        }
37
38
        if ($this->adapter) {
39
            return $this->adapter->log_error($errno, $errstr, $file, $line, $context);
40
        }
41
42
        return false;
43
    }
44
45
    public function log($string, $context = "") {
46
        if ($this->adapter) {
47
            return $this->adapter->log_error(E_USER_NOTICE, $string, '', 0, $context);
48
        }
49
50
        return false;
51
    }
52
53
    public function __construct() {
54
        switch (LOG_DESTINATION) {
0 ignored issues
show
The constant LOG_DESTINATION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
55
        case "sql":
56
            $this->adapter = new Logger_SQL();
57
            break;
58
        case "syslog":
59
            $this->adapter = new Logger_Syslog();
60
            break;
61
        default:
62
            $this->adapter = false;
63
        }
64
    }
65
66
    public static function get(): Logger {
67
        if (self::$instance == null) {
68
            self::$instance = new self();
69
        }
70
        return self::$instance;
71
    }
72
73
}
74