1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WZRD\Logging; |
4
|
|
|
|
5
|
|
|
use Monolog\Logger as Monolog; |
6
|
|
|
use WZRD\Contracts\Logging\Logger; |
7
|
|
|
|
8
|
|
|
class MonologLogger implements Logger |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Monolog instance. |
12
|
|
|
* |
13
|
|
|
* @var Monolog\Logger |
14
|
|
|
*/ |
15
|
|
|
private $monolog; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Initialize logger with Monolog instance. |
19
|
|
|
* |
20
|
|
|
* @param Monolog\Logger $monolog |
21
|
|
|
*/ |
22
|
|
|
public function __construct(Monolog $monolog) |
23
|
|
|
{ |
24
|
|
|
$this->monolog = $monolog; |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* System is unusable. |
29
|
|
|
* |
30
|
|
|
* @param string $message |
31
|
|
|
* @param array $context |
32
|
|
|
*/ |
33
|
|
|
public function emergency($message, array $context = []) |
34
|
|
|
{ |
35
|
|
|
$this->monolog->addEmergency($message, $context); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Action must be taken immediately. |
40
|
|
|
* |
41
|
|
|
* Example: Entire website down, database unavailable, etc. This should |
42
|
|
|
* trigger the SMS alerts and wake you up. |
43
|
|
|
* |
44
|
|
|
* @param string $message |
45
|
|
|
* @param array $context |
46
|
|
|
*/ |
47
|
|
|
public function alert($message, array $context = []) |
48
|
|
|
{ |
49
|
|
|
$this->monolog->addAlert($message, $context); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Critical conditions. |
54
|
|
|
* |
55
|
|
|
* Example: Application component unavailable, unexpected exception. |
56
|
|
|
* |
57
|
|
|
* @param string $message |
58
|
|
|
* @param array $context |
59
|
|
|
*/ |
60
|
|
|
public function critical($message, array $context = []) |
61
|
|
|
{ |
62
|
|
|
$this->monolog->addCritical($message, $context); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Runtime errors that do not require immediate action but should typically |
67
|
|
|
* be logged and monitored. |
68
|
|
|
* |
69
|
|
|
* @param string $message |
70
|
|
|
* @param array $context |
71
|
|
|
*/ |
72
|
|
|
public function error($message, array $context = []) |
73
|
|
|
{ |
74
|
|
|
$this->monolog->addError($message, $context); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Exceptional occurrences that are not errors. |
79
|
|
|
* |
80
|
|
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things |
81
|
|
|
* that are not necessarily wrong. |
82
|
|
|
* |
83
|
|
|
* @param string $message |
84
|
|
|
* @param array $context |
85
|
|
|
*/ |
86
|
|
|
public function warning($message, array $context = []) |
87
|
|
|
{ |
88
|
|
|
$this->monolog->addWarning($message, $context); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Normal but significant events. |
93
|
|
|
* |
94
|
|
|
* @param string $message |
95
|
|
|
* @param array $context |
96
|
|
|
*/ |
97
|
|
|
public function notice($message, array $context = []) |
98
|
|
|
{ |
99
|
|
|
$this->monolog->addNotice($message, $context); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Interesting events. |
104
|
|
|
* |
105
|
|
|
* Example: User logs in, SQL logs. |
106
|
|
|
* |
107
|
|
|
* @param string $message |
108
|
|
|
* @param array $context |
109
|
|
|
*/ |
110
|
|
|
public function info($message, array $context = []) |
111
|
|
|
{ |
112
|
|
|
$this->monolog->addInfo($message, $context); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Detailed debug information. |
117
|
|
|
* |
118
|
|
|
* @param string $message |
119
|
|
|
* @param array $context |
120
|
|
|
*/ |
121
|
|
|
public function debug($message, array $context = []) |
122
|
|
|
{ |
123
|
|
|
$this->monolog->addDebug($message, $context); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Logs with an arbitrary level. |
128
|
|
|
* |
129
|
|
|
* @param mixed $level |
130
|
|
|
* @param string $message |
131
|
|
|
* @param array $context |
132
|
|
|
*/ |
133
|
|
|
public function log($level, $message, array $context = []) |
134
|
|
|
{ |
135
|
|
|
$this->monolog->addRecord($level, $message, $context); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..