1 | <?php declare(strict_types=1); |
||
9 | class Logger extends AbstractLogger |
||
10 | { |
||
11 | const BLACK = 'black'; |
||
12 | const DARK_GRAY = 'dark_gray'; |
||
13 | const BLUE = 'blue'; |
||
14 | const LIGHT_BLUE = 'light_blue'; |
||
15 | const GREEN = 'green'; |
||
16 | const LIGHT_GREEN = 'light_green'; |
||
17 | const CYAN = 'cyan'; |
||
18 | const LIGHT_CYAN = 'light_cyan'; |
||
19 | const RED = 'red'; |
||
20 | const LIGHT_RED = 'light_red'; |
||
21 | const PURPLE = 'purple'; |
||
22 | const LIGHT_PURPLE = 'light_purple'; |
||
23 | const BROWN = 'brown'; |
||
24 | const YELLOW = 'yellow'; |
||
25 | const MAGENTA = 'magenta'; |
||
26 | const LIGHT_GRAY = 'light_gray'; |
||
27 | const WHITE = 'white'; |
||
28 | const DEFAULT = 'default'; |
||
29 | const BOLD = 'bold'; |
||
30 | |||
31 | /** @var resource $resource The file handle */ |
||
32 | protected $resource = null; |
||
33 | |||
34 | /** @var string $level */ |
||
35 | protected $level = LogLevel::INFO; |
||
36 | |||
37 | /** @var bool $closeLocally */ |
||
38 | protected $closeLocally = false; |
||
39 | |||
40 | /** @var bool */ |
||
41 | protected $addDate = true; |
||
42 | |||
43 | /** @var string */ |
||
44 | protected $separator = ' | '; |
||
45 | |||
46 | /** @var \Closure */ |
||
47 | protected $formatter = null; |
||
48 | |||
49 | /** @var string */ |
||
50 | protected $lastLogEntry = ''; |
||
51 | |||
52 | /** @var bool|null */ |
||
53 | protected $gzipFile = null; |
||
54 | |||
55 | /** @var bool */ |
||
56 | protected $useLocking = false; |
||
57 | |||
58 | /** |
||
59 | * @var array $logLevels List of supported levels |
||
60 | */ |
||
61 | static protected $logLevels = [ |
||
62 | LogLevel::EMERGENCY => [1, self::WHITE, self::RED, self::DEFAULT, 'EMERG'], |
||
63 | LogLevel::ALERT => [2, self::WHITE, self::YELLOW, self::DEFAULT, 'ALERT'], |
||
64 | LogLevel::CRITICAL => [3, self::RED, self::DEFAULT, self::BOLD , 'CRIT'], |
||
65 | LogLevel::ERROR => [4, self::RED, self::DEFAULT, self::DEFAULT, 'ERROR'], |
||
66 | LogLevel::WARNING => [5, self::YELLOW, self::DEFAULT, self::DEFAULT, 'WARN'], |
||
67 | LogLevel::NOTICE => [6, self::CYAN, self::DEFAULT, self::DEFAULT, 'NOTE'], |
||
68 | LogLevel::INFO => [7, self::GREEN, self::DEFAULT, self::DEFAULT, 'INFO'], |
||
69 | LogLevel::DEBUG => [8, self::LIGHT_GRAY, self::DEFAULT, self::DEFAULT, 'DEBUG'], |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * @var array |
||
74 | */ |
||
75 | static protected $colours = [ |
||
76 | 'fore' => [ |
||
77 | self::BLACK => '0;30', |
||
78 | self::DARK_GRAY => '1;30', |
||
79 | self::BLUE => '0;34', |
||
80 | self::LIGHT_BLUE => '1;34', |
||
81 | self::GREEN => '0;32', |
||
82 | self::LIGHT_GREEN => '1;32', |
||
83 | self::CYAN => '0;36', |
||
84 | self::LIGHT_CYAN => '1;36', |
||
85 | self::RED => '0;31', |
||
86 | self::LIGHT_RED => '1;31', |
||
87 | self::PURPLE => '0;35', |
||
88 | self::LIGHT_PURPLE => '1;35', |
||
89 | self::BROWN => '0;33', |
||
90 | self::YELLOW => '1;33', |
||
91 | self::MAGENTA => '0;35', |
||
92 | self::LIGHT_GRAY => '0;37', |
||
93 | self::WHITE => '1;37', |
||
94 | ], |
||
95 | 33 | 'back' => [ |
|
96 | self::DEFAULT => '49', |
||
97 | 33 | self::BLACK => '40', |
|
98 | 33 | self::RED => '41', |
|
99 | 33 | self::GREEN => '42', |
|
100 | 33 | self::YELLOW => '43', |
|
101 | 33 | self::BLUE => '44', |
|
102 | 33 | self::MAGENTA => '45', |
|
103 | self::CYAN => '46', |
||
104 | self::LIGHT_GRAY => '47', |
||
105 | ], |
||
106 | self::BOLD => [], |
||
107 | ]; |
||
108 | |||
109 | /** |
||
110 | * @param mixed $resource |
||
111 | * @param string $level |
||
112 | * @param bool $useLocking |
||
113 | * @param bool $gzipFile |
||
114 | * @param bool $addDate |
||
115 | */ |
||
116 | public function __construct($resource, string $level=LogLevel::INFO, bool $useLocking=false, bool $gzipFile=false, bool $addDate=true) |
||
124 | 27 | ||
125 | 27 | /** |
|
126 | * @param $resource |
||
127 | 27 | * @return LoggerInterface |
|
128 | 18 | */ |
|
129 | 24 | public function setLogFile($resource) : LoggerInterface |
|
135 | 16 | ||
136 | /** |
||
137 | 27 | * @param string $string |
|
138 | 27 | * @param string $foregroundColor |
|
139 | * @param string $backgroundColor |
||
140 | * @param bool $bold |
||
141 | * @return string |
||
142 | */ |
||
143 | public static function addColour(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
||
163 | 33 | ||
164 | 33 | /** |
|
165 | * @param string $string |
||
166 | * @param string $foregroundColor |
||
167 | * @param string $backgroundColor |
||
168 | * @param bool $bold |
||
169 | * @return string |
||
170 | */ |
||
171 | public function colourize(string $string, string $foregroundColor='', string $backgroundColor='', bool $bold=false) : string |
||
175 | |||
176 | /** |
||
177 | * @param string $level Ignore logging attempts at a level less the $level |
||
178 | * @return LoggerInterface |
||
179 | 3 | */ |
|
180 | public function setLogLevel(string $level) : LoggerInterface |
||
190 | |||
191 | /** |
||
192 | * @return LoggerInterface |
||
193 | */ |
||
194 | public function lock() : LoggerInterface |
||
200 | |||
201 | /** |
||
202 | * @return LoggerInterface |
||
203 | */ |
||
204 | public function gzipped() : LoggerInterface |
||
210 | 16 | ||
211 | 18 | /** |
|
212 | * @param callable $fnFormatter |
||
213 | 24 | * |
|
214 | 16 | * @return LoggerInterface |
|
215 | */ |
||
216 | public function formatter(callable $fnFormatter) : LoggerInterface |
||
222 | 24 | ||
223 | 24 | /** |
|
224 | * Log messages to resource |
||
225 | * |
||
226 | * @param mixed $level The level of the log message |
||
227 | * @param string|object $message If an object is passed it must implement __toString() |
||
228 | * @param array $context Placeholders to be substituted in the message |
||
229 | * |
||
230 | * @return LoggerInterface |
||
231 | */ |
||
232 | 24 | public function log($level, $message, array $context=[]) : LoggerInterface |
|
254 | |||
255 | 27 | /** |
|
256 | 27 | * @param string $style |
|
257 | 18 | * @param string $message |
|
258 | * @return string |
||
259 | */ |
||
260 | 27 | public static function style(string $style, string $message) : string |
|
268 | 27 | ||
269 | 18 | /** |
|
270 | 27 | * @param string $level |
|
271 | * @param string $message |
||
272 | * @param array $context |
||
273 | * @return string |
||
274 | */ |
||
275 | protected function formatMessage(string $level, string $message, array $context=[]) : string |
||
286 | |||
287 | /** |
||
288 | * Write the content to the stream |
||
289 | * |
||
290 | * @param string $content |
||
291 | */ |
||
292 | public function write(string $content) |
||
305 | |||
306 | /** |
||
307 | * @return mixed|resource |
||
308 | * @throws \Exception |
||
309 | */ |
||
310 | protected function getResource() |
||
326 | |||
327 | /** |
||
328 | * @return string |
||
329 | */ |
||
330 | public function getLastLogEntry() : string |
||
334 | |||
335 | /** |
||
336 | * @return resource |
||
337 | */ |
||
338 | protected function openResource() |
||
347 | |||
348 | public function __destruct() |
||
355 | } |
||
356 | |||
357 |
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..