1 | <?php |
||
15 | class Logger implements LoggerInterface |
||
16 | { |
||
17 | /** |
||
18 | * The array that will collect all the log messages |
||
19 | * |
||
20 | * @see Logger::log() |
||
21 | * @see Logger::getLog() |
||
22 | * @var array |
||
23 | */ |
||
24 | protected $log = array(); |
||
25 | |||
26 | |||
27 | /** |
||
28 | * The callable to format every logged message |
||
29 | * |
||
30 | * @var callable |
||
31 | * @see Logger::defaultFormat() |
||
32 | */ |
||
33 | protected $message_format; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Current logging level (eg 'debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert' or 'emergency') |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $level; |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Logging level mapping, used to hierarchize |
||
46 | * |
||
47 | * This complies to \Psr\Log\LogLevel and RFC 5424 severity values : |
||
48 | * 0 Emergency: system is unusable |
||
49 | * 1 Alert: action must be taken immediately |
||
50 | * 2 Critical: critical conditions |
||
51 | * 3 Error: error conditions |
||
52 | * 4 Warning: warning conditions |
||
53 | * 5 Notice: normal but significant condition |
||
54 | * 6 Informational: informational messages |
||
55 | * 7 Debug: debug-level messages |
||
56 | * |
||
57 | * @var array |
||
58 | */ |
||
59 | protected $log_levels = array( |
||
60 | LogLevel::DEBUG => 7, |
||
61 | LogLevel::INFO => 6, |
||
62 | LogLevel::NOTICE => 5, |
||
63 | LogLevel::WARNING => 4, |
||
64 | LogLevel::ERROR => 3, |
||
65 | LogLevel::CRITICAL => 2, |
||
66 | LogLevel::ALERT => 1, |
||
67 | LogLevel::EMERGENCY => 0, |
||
68 | ); |
||
69 | |||
70 | |||
71 | /** |
||
72 | * @param string $level |
||
73 | */ |
||
74 | 75 | public function __construct($level = LogLevel::DEBUG) |
|
81 | |||
82 | |||
83 | /** |
||
84 | * @param string $message |
||
85 | * @param array $context |
||
86 | * @see Logger::log() |
||
87 | * @return void |
||
88 | */ |
||
89 | 3 | public function emergency($message, array $context = array()) |
|
93 | |||
94 | |||
95 | /** |
||
96 | * @param string $message |
||
97 | * @param array $context |
||
98 | * @see Logger::log() |
||
99 | * @return void |
||
100 | */ |
||
101 | 3 | public function alert($message, array $context = array()) |
|
105 | |||
106 | |||
107 | /** |
||
108 | * @param string $message |
||
109 | * @param array $context |
||
110 | * @see Logger::log() |
||
111 | * @return void |
||
112 | */ |
||
113 | 3 | public function critical($message, array $context = array()) |
|
117 | |||
118 | |||
119 | /** |
||
120 | * @param string $message |
||
121 | * @param array $context |
||
122 | * @see Logger::log() |
||
123 | * @return void |
||
124 | */ |
||
125 | 15 | public function error($message, array $context = array()) |
|
129 | |||
130 | |||
131 | /** |
||
132 | * @param string $message |
||
133 | * @param array $context |
||
134 | * @see Logger::log() |
||
135 | * @return void |
||
136 | */ |
||
137 | 3 | public function warning($message, array $context = array()) |
|
141 | |||
142 | |||
143 | /** |
||
144 | * @param string $message |
||
145 | * @param array $context |
||
146 | * @see Logger::log() |
||
147 | * @return void |
||
148 | */ |
||
149 | 3 | public function notice($message, array $context = array()) |
|
153 | |||
154 | |||
155 | /** |
||
156 | * @param string $message |
||
157 | * @param array $context |
||
158 | * @see Logger::log() |
||
159 | * @return void |
||
160 | */ |
||
161 | 3 | public function info($message, array $context = array()) |
|
165 | |||
166 | /** |
||
167 | * @param string $message |
||
168 | * @param array $context |
||
169 | * @see Logger::log() |
||
170 | * @return void |
||
171 | */ |
||
172 | 9 | public function debug($message, array $context = array()) |
|
176 | |||
177 | |||
178 | /** |
||
179 | * @param string $level |
||
180 | * @param mixed $message |
||
181 | * @param array $context |
||
182 | * @throws InvalidArgumentException |
||
183 | * @return void |
||
184 | */ |
||
185 | 45 | public function log($level, $message, array $context = array()) |
|
203 | |||
204 | |||
205 | /** |
||
206 | * @param string $level |
||
207 | * @throws InvalidArgumentException |
||
208 | * @return bool |
||
209 | */ |
||
210 | 75 | public function isLogLevel($level) { |
|
217 | |||
218 | |||
219 | /** |
||
220 | * @return bool |
||
221 | */ |
||
222 | 39 | public function shouldLog($level) { |
|
225 | |||
226 | |||
227 | /** |
||
228 | * As per PSR-3, messages can be a string, or an object with a __toString() method |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | 45 | public function isStringable($message) { |
|
243 | |||
244 | |||
245 | /** |
||
246 | * @return array |
||
247 | */ |
||
248 | 39 | public function getLog() |
|
252 | |||
253 | /** |
||
254 | * @param string $level |
||
255 | * @param string $message |
||
256 | * @param array $context |
||
257 | * @return array |
||
258 | */ |
||
259 | 36 | public function defaultFormat($level, $message, array $context = array()) |
|
271 | |||
272 | |||
273 | /** |
||
274 | * @param array $context |
||
275 | * @return array |
||
276 | */ |
||
277 | 6 | public function formatContext($context) { |
|
300 | |||
301 | |||
302 | /** |
||
303 | * @param callable $message_format |
||
304 | * @return void |
||
305 | */ |
||
306 | 72 | public function setMessageFormat($message_format) |
|
310 | |||
311 | |||
312 | /** |
||
313 | * @return callable |
||
314 | */ |
||
315 | 42 | public function getMessageFormat() |
|
319 | |||
320 | |||
321 | /** |
||
322 | * @param string $level |
||
323 | * @return void |
||
324 | */ |
||
325 | 3 | public function setLevel($level) |
|
329 | |||
330 | |||
331 | /** |
||
332 | * @return int |
||
333 | */ |
||
334 | 24 | public function getLevel() |
|
338 | |||
339 | } |
||
340 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.