1 | <?php |
||
23 | abstract class AbstractLogger extends PsrAbstractLogger |
||
24 | { |
||
25 | /** |
||
26 | * The PSR-3 logging levels. |
||
27 | * @var array |
||
28 | */ |
||
29 | protected static $levels = array( |
||
30 | 'emergency', |
||
31 | 'alert', |
||
32 | 'critical', |
||
33 | 'error', |
||
34 | 'warning', |
||
35 | 'notice', |
||
36 | 'info', |
||
37 | 'debug' |
||
38 | ); |
||
39 | |||
40 | /** |
||
41 | * Holds the minimal level index supported by this logger. |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $min_level = 7; |
||
45 | |||
46 | /** |
||
47 | * Whether this logger will cascade downstream. |
||
48 | * @var bool |
||
49 | */ |
||
50 | protected $cascading = true; |
||
51 | |||
52 | /** |
||
53 | * Whether this logger will be deferred (push the logs at destruct time). |
||
54 | * @var bool |
||
55 | */ |
||
56 | protected $deferred = false; |
||
57 | |||
58 | /** |
||
59 | * Holds the deferred logs. |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $deferred_logs = array(); |
||
63 | |||
64 | /** |
||
65 | * Holds the log formatter. |
||
66 | * @var LogFormatter|null |
||
67 | */ |
||
68 | protected $log_formatter = null; |
||
69 | |||
70 | /** |
||
71 | * Holds the logger options (useful to set default options). |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $options = array(); |
||
75 | |||
76 | /** |
||
77 | * Gets the named level code. |
||
78 | * |
||
79 | * @param string $level_name The name of a PSR-3 level. |
||
80 | * @return int |
||
81 | * @throws InvalidArgumentException |
||
82 | */ |
||
83 | 740 | public static function getLevelCode($level_name) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 728 | public function log($level, $message, array $context = array()) |
|
104 | |||
105 | /** |
||
106 | * Processes the given log. |
||
107 | * |
||
108 | * @param LogEntry $log The log entry to process. |
||
109 | * @return bool Wether this logger cascade downstream. |
||
110 | */ |
||
111 | 700 | public function process(LogEntry $log) |
|
121 | |||
122 | /** |
||
123 | * Checks whether the given level code is handled by this logger. |
||
124 | * |
||
125 | * @param int $level_code |
||
126 | * @return bool |
||
127 | */ |
||
128 | 36 | public function isHandling($level_code) |
|
132 | |||
133 | /** |
||
134 | * Sets the minimal level at which this logger will be triggered. |
||
135 | * |
||
136 | * @param string $name |
||
137 | * @param bool|true $cascading Should the logs continue pass that level. |
||
138 | * @return self |
||
139 | */ |
||
140 | 36 | public function setMinLevel($name, $cascading = true) |
|
147 | |||
148 | /** |
||
149 | * Alias to self::setMinLevel(). |
||
150 | * |
||
151 | * @param string $name |
||
152 | * @param bool|false $blocking Should the logs continue pass that level. |
||
153 | * @return self |
||
154 | */ |
||
155 | 4 | public function interceptAt($name, $blocking = false) |
|
159 | |||
160 | /** |
||
161 | * Returns the minimal level at which this logger will be triggered. |
||
162 | * |
||
163 | * @return int |
||
164 | */ |
||
165 | 28 | public function getMinLevel() |
|
169 | |||
170 | /** |
||
171 | * Sets wether to enable/disable cascading. |
||
172 | * |
||
173 | * @param bool $bool |
||
174 | * @return self |
||
175 | */ |
||
176 | 12 | public function setCascading($bool) |
|
182 | |||
183 | /** |
||
184 | * Sets wether to enable/disable log deferring. |
||
185 | * |
||
186 | * @param bool $bool |
||
187 | * @return self |
||
188 | */ |
||
189 | 16 | public function setDeferred($bool) |
|
195 | |||
196 | /** |
||
197 | * Returns all the deferred logs. |
||
198 | * |
||
199 | * @return array |
||
200 | */ |
||
201 | 8 | public function getDeferredLogs() |
|
205 | |||
206 | /** |
||
207 | * Process any accumulated deferred log if there are any. |
||
208 | */ |
||
209 | 796 | final public function __destruct() |
|
233 | |||
234 | /** |
||
235 | * Closes the logger ~ acts as the last resort garbage collector. |
||
236 | * |
||
237 | * This method is called last at __destruct() time. |
||
238 | */ |
||
239 | 154 | public function close() |
|
243 | |||
244 | /** |
||
245 | * Sets a log formatter. |
||
246 | * |
||
247 | * @param LogFormatter $formatter |
||
248 | */ |
||
249 | 724 | public function setLogFormatter(LogFormatter $formatter) |
|
253 | |||
254 | /** |
||
255 | * Returns the current log formatter. |
||
256 | * |
||
257 | * @return LogFormatter |
||
258 | */ |
||
259 | 724 | public function getLogFormatter() |
|
267 | |||
268 | /** |
||
269 | * Sets and merges the options for this logger, overriding any default. |
||
270 | * |
||
271 | * @param array|null $options |
||
272 | */ |
||
273 | public function setOptions(array $options=null) |
||
279 | |||
280 | } |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: