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') { |
||
84 | |||
85 | |||
86 | |||
87 | /** |
||
88 | * Logs with an arbitrary level. |
||
89 | * |
||
90 | * @param mixed $level |
||
91 | * @param string $message |
||
92 | * @param array $context |
||
93 | * @return null |
||
94 | */ |
||
95 | public function log($level, $message, array $context = array()) { |
||
98 | |||
99 | |||
100 | |||
101 | /** |
||
102 | * System is unusable. |
||
103 | * |
||
104 | * @param string $message |
||
105 | * @param array $context |
||
106 | * @return null |
||
107 | */ |
||
108 | public function emergency($message, array $context = array()) { |
||
111 | |||
112 | |||
113 | |||
114 | /** |
||
115 | * Action must be taken immediately. |
||
116 | * |
||
117 | * Example: Entire website down, database unavailable, etc. This should |
||
118 | * trigger the SMS alerts and wake you up. |
||
119 | * |
||
120 | * @param string $message |
||
121 | * @param array $context |
||
122 | * @return null |
||
123 | */ |
||
124 | public function alert($message, array $context = array()) { |
||
127 | |||
128 | |||
129 | |||
130 | /** |
||
131 | * Critical conditions. |
||
132 | * |
||
133 | * Example: Application component unavailable, unexpected exception. |
||
134 | * |
||
135 | * @param string $message |
||
136 | * @param array $context |
||
137 | * @return null |
||
138 | */ |
||
139 | public function critical($message, array $context = array()) { |
||
142 | |||
143 | |||
144 | |||
145 | /** |
||
146 | * Runtime errors that do not require immediate action but should typically |
||
147 | * be logged and monitored. |
||
148 | * |
||
149 | * @param string $message |
||
150 | * @param array $context |
||
151 | * @return null |
||
152 | */ |
||
153 | public function error($message, array $context = array()) { |
||
156 | |||
157 | |||
158 | |||
159 | /** |
||
160 | * Exceptional occurrences that are not errors. |
||
161 | * |
||
162 | * Example: Use of deprecated APIs, poor use of an API, undesirable things |
||
163 | * that are not necessarily wrong. |
||
164 | * |
||
165 | * @param string $message |
||
166 | * @param array $context |
||
167 | * @return null |
||
168 | */ |
||
169 | public function warning($message, array $context = array()) { |
||
172 | |||
173 | |||
174 | |||
175 | /** |
||
176 | * Normal but significant events. |
||
177 | * |
||
178 | * @param string $message |
||
179 | * @param array $context |
||
180 | * @return null |
||
181 | */ |
||
182 | public function notice($message, array $context = array()) { |
||
185 | |||
186 | |||
187 | |||
188 | /** |
||
189 | * Interesting events. |
||
190 | * |
||
191 | * Example: User logs in, SQL logs. |
||
192 | * |
||
193 | * @param string $message |
||
194 | * @param array $context |
||
195 | * @return null |
||
196 | */ |
||
197 | public function info($message, array $context = array()) { |
||
200 | |||
201 | |||
202 | |||
203 | /** |
||
204 | * Detailed debug information. |
||
205 | * |
||
206 | * @param string $message |
||
207 | * @param array $context |
||
208 | * @return null |
||
209 | */ |
||
210 | public function debug($message, array $context = array()) { |
||
213 | } |
||
214 | |||
217 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.