|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ubiquity\log; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Logger { |
|
6
|
|
|
/** |
|
7
|
|
|
* @var Logger |
|
8
|
|
|
*/ |
|
9
|
|
|
private static $instance; |
|
10
|
|
|
private static $test; |
|
11
|
|
|
|
|
12
|
|
|
private static function createLogger(&$config){ |
|
13
|
|
|
if(is_callable($logger=$config["logger"])){ |
|
14
|
|
|
$instance=$logger(); |
|
15
|
|
|
}else{ |
|
16
|
|
|
$instance=$config["logger"]; |
|
17
|
|
|
} |
|
18
|
|
|
if($instance instanceof Logger){ |
|
19
|
|
|
self::$instance=$instance; |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public static function inContext($contexts,$context){ |
|
24
|
|
|
if($contexts===null){ |
|
25
|
|
|
return true; |
|
26
|
|
|
} |
|
27
|
|
|
return array_search($context, $contexts)!==false; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public static function init(&$config) { |
|
31
|
|
|
if(self::$test=isset($config["logger"]) && $config["debug"]===true){ |
|
|
|
|
|
|
32
|
|
|
self::createLogger($config); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public static function log($level,$context, $message,$part=null,$extra=null) { |
|
37
|
|
|
if (self::$test) |
|
38
|
|
|
return self::$instance->_log($level,$context, $message,$part,$extra) ; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public static function info($context, $message,$part=null,$extra=null) { |
|
42
|
|
|
if (self::$test) |
|
43
|
|
|
return self::$instance->_info($context, $message,$part,$extra) ; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function warn($context, $message,$part=null,$extra=null) { |
|
47
|
|
|
if (self::$test) |
|
48
|
|
|
return self::$instance->_warn($context, $message,$part,$extra) ; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public static function error($context, $message,$part=null,$extra=null) { |
|
52
|
|
|
if (self::$test) |
|
53
|
|
|
return self::$instance->_error($context, $message,$part,$extra) ; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function critical($context, $message,$part=null,$extra=null) { |
|
57
|
|
|
if (self::$test) |
|
58
|
|
|
return self::$instance->_critical($context, $message,$part,$extra) ; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public static function alert($context, $message,$part=null,$extra=null) { |
|
62
|
|
|
if (self::$test) |
|
63
|
|
|
return self::$instance->_alert($context, $message,$part,$extra) ; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public static function asObjects($reverse=true,$maxlines=10,$contexts=null){ |
|
67
|
|
|
if (self::$test) |
|
68
|
|
|
return self::$instance->_asObjects($reverse,$maxlines,$contexts); |
|
69
|
|
|
return []; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public static function clearAll(){ |
|
73
|
|
|
if (self::$test){ |
|
74
|
|
|
self::$instance->_clearAll(); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
abstract public function _log($level,$context, $message,$part,$extra); |
|
79
|
|
|
abstract public function _info($context, $message,$part,$extra); |
|
80
|
|
|
abstract public function _warn($context, $message,$part,$extra); |
|
81
|
|
|
abstract public function _error($context, $message,$part,$extra); |
|
82
|
|
|
abstract public function _critical($context, $message,$part,$extra); |
|
83
|
|
|
abstract public function _alert($context, $message,$part,$extra); |
|
84
|
|
|
abstract public function _asObjects($reverse=true,$maxlines=10,$contexts=null); |
|
85
|
|
|
abstract public function _clearAll(); |
|
86
|
|
|
} |
|
87
|
|
|
|