1 | <?php |
||
20 | class CLogger |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * Constans for loglevel. |
||
25 | * |
||
26 | */ |
||
27 | const EMERGENCY = 'emergency'; |
||
28 | const ALERT = 'alert'; |
||
29 | const CRITICAL = 'critical'; |
||
30 | const ERROR = 'error'; |
||
31 | const WARNING = 'warning'; |
||
32 | const NOTICE = 'notice'; |
||
33 | const INFO = 'info'; |
||
34 | const DEBUG = 'debug'; |
||
35 | |||
36 | |||
37 | |||
38 | /** |
||
39 | * Constans for loglevel. |
||
40 | * |
||
41 | */ |
||
42 | private $context = 'development'; // production, development or debug |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * Init the logger depending on its context production, development or debug. |
||
48 | * |
||
49 | * @param string $context as production, development or debug, default is development |
||
50 | * @return $this |
||
51 | */ |
||
52 | public function setContext($context = 'development') |
||
82 | |||
83 | |||
84 | |||
85 | /** |
||
86 | * Logs with an arbitrary level. |
||
87 | * |
||
88 | * @param mixed $level |
||
89 | * @param string $message |
||
90 | * @param array $context |
||
91 | * @return null |
||
92 | */ |
||
93 | public function log($level, $message, array $context = []) |
||
99 | |||
100 | |||
101 | |||
102 | /** |
||
103 | * System is unusable. |
||
104 | * |
||
105 | * @param string $message |
||
106 | * @param array $context |
||
107 | * @return null |
||
108 | */ |
||
109 | public function emergency($message, array $context = array()) |
||
113 | |||
114 | |||
115 | |||
116 | /** |
||
117 | * Action must be taken immediately. |
||
118 | * |
||
119 | * Example: Entire website down, database unavailable, etc. This should |
||
120 | * trigger the SMS alerts and wake you up. |
||
121 | * |
||
122 | * @param string $message |
||
123 | * @param array $context |
||
124 | * @return null |
||
125 | */ |
||
126 | public function alert($message, array $context = array()) |
||
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * Critical conditions. |
||
135 | * |
||
136 | * Example: Application component unavailable, unexpected exception. |
||
137 | * |
||
138 | * @param string $message |
||
139 | * @param array $context |
||
140 | * @return null |
||
141 | */ |
||
142 | public function critical($message, array $context = array()) |
||
146 | |||
147 | |||
148 | |||
149 | /** |
||
150 | * Runtime errors that do not require immediate action but should typically |
||
151 | * be logged and monitored. |
||
152 | * |
||
153 | * @param string $message |
||
154 | * @param array $context |
||
155 | * @return null |
||
156 | */ |
||
157 | public function error($message, array $context = array()) |
||
161 | |||
162 | |||
163 | |||
164 | /** |
||
165 | * Exceptional occurrences that are not errors. |
||
166 | * |
||
167 | * Example: Use of deprecated APIs, poor use of an API, undesirable things |
||
168 | * that are not necessarily wrong. |
||
169 | * |
||
170 | * @param string $message |
||
171 | * @param array $context |
||
172 | * @return null |
||
173 | */ |
||
174 | public function warning($message, array $context = array()) |
||
178 | |||
179 | |||
180 | |||
181 | /** |
||
182 | * Normal but significant events. |
||
183 | * |
||
184 | * @param string $message |
||
185 | * @param array $context |
||
186 | * @return null |
||
187 | */ |
||
188 | public function notice($message, array $context = array()) |
||
192 | |||
193 | |||
194 | |||
195 | /** |
||
196 | * Interesting events. |
||
197 | * |
||
198 | * Example: User logs in, SQL logs. |
||
199 | * |
||
200 | * @param string $message |
||
201 | * @param array $context |
||
202 | * @return null |
||
203 | */ |
||
204 | public function info($message, array $context = array()) |
||
208 | |||
209 | |||
210 | |||
211 | /** |
||
212 | * Detailed debug information. |
||
213 | * |
||
214 | * @param string $message |
||
215 | * @param array $context |
||
216 | * @return null |
||
217 | */ |
||
218 | public function debug($message, array $context = array()) |
||
222 | } |
||
223 |
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of
return
,die
orexit
statements that have been added for debug purposes.In the above example, the last
return false
will never be executed, because a return statement has already been met in every possible execution path.