1 | <?php |
||
8 | class Logger extends AbstractLogger |
||
9 | { |
||
10 | /** @var resource $resource The file handle */ |
||
11 | protected $resource = null; |
||
12 | |||
13 | /** @var string $level */ |
||
14 | protected $level = LogLevel::INFO; |
||
15 | |||
16 | /** @var bool $closeLocally */ |
||
17 | protected $closeLocally = false; |
||
18 | |||
19 | /** @var bool */ |
||
20 | protected $addDate = true; |
||
21 | |||
22 | /** @var string */ |
||
23 | protected $separator = ' | '; |
||
24 | |||
25 | /** @var \Closure */ |
||
26 | protected $formatter = null; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $lastLogEntry = ''; |
||
30 | |||
31 | /** @var bool|null */ |
||
32 | protected $gzipFile = null; |
||
33 | |||
34 | /** @var bool */ |
||
35 | protected $useLocking = false; |
||
36 | |||
37 | /** |
||
38 | * @var array $logLevels List of supported levels |
||
39 | */ |
||
40 | protected $logLevels = [ |
||
41 | LogLevel::EMERGENCY => [1, 'white', 'red', 'default', 'EMERG'], |
||
42 | LogLevel::ALERT => [2, 'white', 'yellow', 'default', 'ALERT'], |
||
43 | LogLevel::CRITICAL => [3,'red', 'default', 'bold' , 'CRIT'], |
||
44 | LogLevel::ERROR => [4,'red', 'default', 'default', 'ERROR'], |
||
45 | LogLevel::WARNING => [5, 'yellow', 'default', 'default', 'WARN'], |
||
46 | LogLevel::NOTICE => [6, 'cyan', 'default', 'default', 'NOTE'], |
||
47 | LogLevel::INFO => [7, 'green', 'default', 'default', 'INFO'], |
||
48 | LogLevel::DEBUG => [8, 'dark_gray', 'default', 'default', 'DEBUG'], |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | static protected $colours = [ |
||
55 | 'fore' => [ |
||
56 | 'black' => '0;30', |
||
57 | 'dark_gray' => '1;30', |
||
58 | 'blue' => '0;34', |
||
59 | 'light_blue' => '1;34', |
||
60 | 'green' => '0;32', |
||
61 | 'light_green' => '1;32', |
||
62 | 'cyan' => '0;36', |
||
63 | 'light_cyan' => '1;36', |
||
64 | 'red' => '0;31', |
||
65 | 'light_red' => '1;31', |
||
66 | 'purple' => '0;35', |
||
67 | 'light_purple' => '1;35', |
||
68 | 'brown' => '0;33', |
||
69 | 'yellow' => '1;33', |
||
70 | 'magenta' => '0;35', |
||
71 | 'light_gray' => '0;37', |
||
72 | 'white' => '1;37', |
||
73 | ], |
||
74 | 'back' => [ |
||
75 | 'default' => '49', |
||
76 | 'black' => '40', |
||
77 | 'red' => '41', |
||
78 | 'green' => '42', |
||
79 | 'yellow' => '43', |
||
80 | 'blue' => '44', |
||
81 | 'magenta' => '45', |
||
82 | 'cyan' => '46', |
||
83 | 'light_gray' => '47', |
||
84 | ], |
||
85 | 'bold' => [], |
||
86 | ]; |
||
87 | |||
88 | /** |
||
89 | * @param mixed $resource |
||
90 | * @param string $level |
||
91 | * @param bool $useLocking |
||
92 | * @param bool $gzipFile |
||
93 | * @param bool $addDate |
||
94 | */ |
||
95 | 33 | public function __construct($resource, $level=LogLevel::INFO, $useLocking=false, $gzipFile=false, $addDate=true) |
|
103 | |||
104 | /** |
||
105 | * @param $resource |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function setLogFile($resource) |
||
113 | |||
114 | /** |
||
115 | * @param $string |
||
116 | * @param null $foregroundColor |
||
117 | * @param null $backgroundColor |
||
118 | * @param bool $bold |
||
119 | * @return string |
||
120 | */ |
||
121 | 27 | public static function addColour($string, $foregroundColor=null, $backgroundColor=null, $bold=false) |
|
140 | |||
141 | /** |
||
142 | * @param $string |
||
143 | * @param null $foregroundColor |
||
144 | * @param null $backgroundColor |
||
145 | * @param bool|false $bold |
||
146 | * @return string |
||
147 | */ |
||
148 | 27 | public function colourize($string, $foregroundColor = null, $backgroundColor = null, $bold=false) |
|
152 | |||
153 | /** |
||
154 | * @param string $level Ignore logging attempts at a level less the $level |
||
155 | * @return static |
||
156 | */ |
||
157 | 33 | public function setLogLevel($level) |
|
166 | |||
167 | /** |
||
168 | * @return $this |
||
169 | */ |
||
170 | public function lock() |
||
175 | |||
176 | /** |
||
177 | * @return $this |
||
178 | */ |
||
179 | 3 | public function gzipped() |
|
184 | |||
185 | /** |
||
186 | * @param callable $fnFormatter |
||
187 | * |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function formatter(callable $fnFormatter) |
||
195 | |||
196 | /** |
||
197 | * Log messages to resource |
||
198 | * |
||
199 | * @param mixed $level The level of the log message |
||
200 | * @param string|object $message If an object is passed it must implement __toString() |
||
201 | * @param array $context Placeholders to be substituted in the message |
||
202 | * |
||
203 | * @return static |
||
204 | */ |
||
205 | 24 | public function log($level, $message, array $context = []) |
|
225 | |||
226 | /** |
||
227 | * @param $level |
||
228 | * @param $message |
||
229 | * @param array $context |
||
230 | * @return string |
||
231 | */ |
||
232 | 24 | protected function formatMessage($level, $message, array $context = []) |
|
242 | |||
243 | /** |
||
244 | * Write the content to the stream |
||
245 | * |
||
246 | * @param string $content |
||
247 | */ |
||
248 | 27 | public function write($content) |
|
261 | |||
262 | /** |
||
263 | * @return mixed|resource |
||
264 | * @throws \Exception |
||
265 | */ |
||
266 | 27 | protected function getResource() |
|
281 | |||
282 | /** |
||
283 | * @return string |
||
284 | */ |
||
285 | public function getLastLogEntry() |
||
289 | |||
290 | /** |
||
291 | * @return resource |
||
292 | */ |
||
293 | protected function openResource() |
||
301 | |||
302 | public function __destruct() |
||
309 | } |
||
310 | |||
311 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..