1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\WebServer\Loggers\DummyLogger |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Johann Zelger <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/server |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Server\Loggers; |
22
|
|
|
|
23
|
|
|
use Psr\Log\LogLevel; |
24
|
|
|
use Psr\Log\LoggerInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class DummyLogger |
28
|
|
|
* |
29
|
|
|
* @author Johann Zelger <[email protected]> |
30
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/appserver-io/server |
33
|
|
|
* @link http://www.appserver.io |
34
|
|
|
*/ |
35
|
|
|
class DummyLogger implements LoggerInterface |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The channel name we log to. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $channelName; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Array with the handlers. |
47
|
|
|
* |
48
|
|
|
* @var array |
49
|
|
|
*/ |
50
|
|
|
protected $handlers; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Array with the processors. |
54
|
|
|
* |
55
|
|
|
* @var array |
56
|
|
|
*/ |
57
|
|
|
protected $processors; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The log level we want to use. |
61
|
|
|
* |
62
|
|
|
* @var integer |
63
|
|
|
*/ |
64
|
|
|
protected $logLevel; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The available log levels. |
68
|
|
|
* |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
protected $logLevels = array( |
72
|
|
|
LogLevel::DEBUG => 100, // Detailed debug information. |
73
|
|
|
LogLevel::INFO => 200, // Interesting events. Examples: User logs in, SQL logs. |
74
|
|
|
LogLevel::NOTICE => 250, // Normal but significant events. |
75
|
|
|
LogLevel::WARNING => 300, // Exceptional occurrences that are not errors. Examples: Use of deprecated APIs, poor use of an API, undesirable things that are not necessarily wrong. |
76
|
|
|
LogLevel::ERROR => 400, // Runtime errors that do not require immediate action but should typically be logged and monitored. |
77
|
|
|
LogLevel::CRITICAL => 500, // Critical conditions. Example: Application component unavailable, unexpected exception. |
78
|
|
|
LogLevel::ALERT => 550, // Action must be taken immediately. Example: Entire website down, database unavailable, etc. This should trigger the SMS alerts and wake you up. |
79
|
|
|
LogLevel::EMERGENCY => 600, // Emergency: system is unusable. |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Initializes the logger instance with the log level. |
84
|
|
|
* |
85
|
|
|
* @param string $channelName The channel name |
86
|
|
|
* @param array $handlers The array with the handlers |
87
|
|
|
* @param array $processors The array with the processors |
88
|
|
|
* @param integer $logLevel The log level we want to use |
89
|
|
|
*/ |
90
|
|
|
public function __construct($channelName, array $handlers = array(), array $processors = array(), $logLevel = LogLevel::INFO) |
91
|
|
|
{ |
92
|
|
|
$this->channelName = $channelName; |
93
|
|
|
$this->handlers = $handlers; |
94
|
|
|
$this->processors = $processors; |
95
|
|
|
$this->logLevel = $logLevel; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* System is unusable. |
100
|
|
|
* |
101
|
|
|
* @param string $message The message to log |
102
|
|
|
* @param array $context The context for log |
103
|
|
|
* |
104
|
|
|
* @return null |
105
|
|
|
*/ |
106
|
|
|
public function emergency($message, array $context = array()) |
107
|
|
|
{ |
108
|
|
|
$this->log($message, $context); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Action must be taken immediately. |
113
|
|
|
* |
114
|
|
|
* Example: Entire website down, database unavailable, etc. This should |
115
|
|
|
* trigger the SMS alerts and wake you up. |
116
|
|
|
* |
117
|
|
|
* @param string $message The message to log |
118
|
|
|
* @param array $context The context for log |
119
|
|
|
* |
120
|
|
|
* @return null |
121
|
|
|
*/ |
122
|
|
|
public function alert($message, array $context = array()) |
123
|
|
|
{ |
124
|
|
|
$this->log($message, $context); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Critical conditions. |
129
|
|
|
* |
130
|
|
|
* Example: Application component unavailable, unexpected exception. |
131
|
|
|
* |
132
|
|
|
* @param string $message The message to log |
133
|
|
|
* @param array $context The context for log |
134
|
|
|
* |
135
|
|
|
* @return null |
136
|
|
|
*/ |
137
|
|
|
public function critical($message, array $context = array()) |
138
|
|
|
{ |
139
|
|
|
$this->log($message, $context); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Runtime errors that do not require immediate action but should typically |
144
|
|
|
* be logged and monitored. |
145
|
|
|
* |
146
|
|
|
* @param string $message The message to log |
147
|
|
|
* @param array $context The context for log |
148
|
|
|
* |
149
|
|
|
* @return null |
150
|
|
|
*/ |
151
|
|
|
public function error($message, array $context = array()) |
152
|
|
|
{ |
153
|
|
|
$this->log($message, $context); |
|
|
|
|
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Exceptional occurrences that are not errors. |
158
|
|
|
* |
159
|
|
|
* Example: Use of deprecated APIs, poor use of an API, undesirable things |
160
|
|
|
* that are not necessarily wrong. |
161
|
|
|
* |
162
|
|
|
* @param string $message The message to log |
163
|
|
|
* @param array $context The context for log |
164
|
|
|
* |
165
|
|
|
* @return null |
166
|
|
|
*/ |
167
|
|
|
public function warning($message, array $context = array()) |
168
|
|
|
{ |
169
|
|
|
$this->log($message, $context); |
|
|
|
|
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Normal but significant events. |
174
|
|
|
* |
175
|
|
|
* @param string $message The message to log |
176
|
|
|
* @param array $context The context for log |
177
|
|
|
* |
178
|
|
|
* @return null |
179
|
|
|
*/ |
180
|
|
|
public function notice($message, array $context = array()) |
181
|
|
|
{ |
182
|
|
|
$this->log($message, $context); |
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Interesting events. |
187
|
|
|
* |
188
|
|
|
* Example: User logs in, SQL logs. |
189
|
|
|
* |
190
|
|
|
* @param string $message The message to log |
191
|
|
|
* @param array $context The context for log |
192
|
|
|
* |
193
|
|
|
* @return null |
194
|
|
|
*/ |
195
|
|
|
public function info($message, array $context = array()) |
196
|
|
|
{ |
197
|
|
|
$this->log($message, $context); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Detailed debug information. |
202
|
|
|
* |
203
|
|
|
* @param string $message The message to log |
204
|
|
|
* @param array $context The context for log |
205
|
|
|
* |
206
|
|
|
* @return null |
207
|
|
|
*/ |
208
|
|
|
public function debug($message, array $context = array()) |
209
|
|
|
{ |
210
|
|
|
$this->log($message, $context); |
|
|
|
|
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Logs with an arbitrary level. |
215
|
|
|
* |
216
|
|
|
* @param mixed $level The log level |
217
|
|
|
* @param string $message The message to log |
218
|
|
|
* @param array $context The context for log |
219
|
|
|
* |
220
|
|
|
* @return null |
221
|
|
|
*/ |
222
|
|
|
public function log($level, $message, array $context = array()) |
223
|
|
|
{ |
224
|
|
|
// this is a dummy logger |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Returns the log level we want to use. |
229
|
|
|
* |
230
|
|
|
* @return integer The log level |
231
|
|
|
*/ |
232
|
|
|
protected function getLogLevel() |
233
|
|
|
{ |
234
|
|
|
return $this->logLevel; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Checks if the message should be logged, depending on the log level. |
239
|
|
|
* |
240
|
|
|
* @param string $logLevel The log level to match against |
241
|
|
|
* |
242
|
|
|
* @return boolean TRUE if the message should be logged, else FALSE |
243
|
|
|
*/ |
244
|
|
|
protected function shouldLog($logLevel) |
245
|
|
|
{ |
246
|
|
|
return $this->logLevels[$logLevel] >= $this->logLevels[$this->getLogLevel()]; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: