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 | protected $addDate = true; |
||
20 | |||
21 | protected $separator = ' | '; |
||
22 | |||
23 | protected $formatter = null; |
||
24 | |||
25 | protected $lastLogEntry = ''; |
||
26 | |||
27 | protected $gzipFile = null; |
||
28 | |||
29 | protected $useLocking = false; |
||
30 | |||
31 | /** |
||
32 | * @var array $logLevels List of supported levels |
||
33 | */ |
||
34 | protected $logLevels = [ |
||
35 | LogLevel::EMERGENCY => [1, 'white', 'red', 'default', 'EMERG'], |
||
36 | LogLevel::ALERT => [2, 'white', 'yellow', 'default', 'ALERT'], |
||
37 | LogLevel::CRITICAL => [3,'red', 'default', 'bold' , 'CRIT'], |
||
38 | LogLevel::ERROR => [4,'red', 'default', 'default', 'ERROR'], |
||
39 | LogLevel::WARNING => [5, 'yellow', 'default', 'default', 'WARN'], |
||
40 | LogLevel::NOTICE => [6, 'cyan', 'default', 'default', 'NOTE'], |
||
41 | LogLevel::INFO => [7, 'green', 'default', 'default', 'INFO'], |
||
42 | LogLevel::DEBUG => [8, 'dark_gray', 'default', 'default', 'DEBUG'], |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * @var array |
||
47 | */ |
||
48 | static protected $colours = [ |
||
49 | 'fore' => [ |
||
50 | 'black' => '0;30', |
||
51 | 'dark_gray' => '1;30', |
||
52 | 'blue' => '0;34', |
||
53 | 'light_blue' => '1;34', |
||
54 | 'green' => '0;32', |
||
55 | 'light_green' => '1;32', |
||
56 | 'cyan' => '0;36', |
||
57 | 'light_cyan' => '1;36', |
||
58 | 'red' => '0;31', |
||
59 | 'light_red' => '1;31', |
||
60 | 'purple' => '0;35', |
||
61 | 'light_purple' => '1;35', |
||
62 | 'brown' => '0;33', |
||
63 | 'yellow' => '1;33', |
||
64 | 'magenta' => '0;35', |
||
65 | 'light_gray' => '0;37', |
||
66 | 'white' => '1;37', |
||
67 | ], |
||
68 | 'back' => [ |
||
69 | 'default' => '49', |
||
70 | 'black' => '40', |
||
71 | 'red' => '41', |
||
72 | 'green' => '42', |
||
73 | 'yellow' => '43', |
||
74 | 'blue' => '44', |
||
75 | 'magenta' => '45', |
||
76 | 'cyan' => '46', |
||
77 | 'light_gray' => '47', |
||
78 | ], |
||
79 | 'bold' => [], |
||
80 | ]; |
||
81 | |||
82 | /** |
||
83 | * @param mixed $resource |
||
84 | * @param string $level |
||
85 | * @param bool $useLocking |
||
86 | * @param bool $gzipFile |
||
87 | * @param bool $addDate |
||
88 | */ |
||
89 | 33 | public function __construct($resource, $level=LogLevel::INFO, $useLocking=false, $gzipFile=false, $addDate=true) |
|
97 | |||
98 | /** |
||
99 | * @param $resource |
||
100 | * @return $this |
||
101 | */ |
||
102 | public function setLogFile($resource) |
||
107 | |||
108 | /** |
||
109 | * @param $string |
||
110 | * @param null $foregroundColor |
||
111 | * @param null $backgroundColor |
||
112 | * @param bool $bold |
||
113 | * @return string |
||
114 | */ |
||
115 | 27 | public static function addColour($string, $foregroundColor=null, $backgroundColor=null, $bold=false) |
|
132 | |||
133 | /** |
||
134 | * @param $string |
||
135 | * @param null $foregroundColor |
||
136 | * @param null $backgroundColor |
||
137 | * @param bool|false $bold |
||
138 | * @return string |
||
139 | */ |
||
140 | 27 | public function colourize($string, $foregroundColor = null, $backgroundColor = null, $bold=false) |
|
144 | |||
145 | /** |
||
146 | * @param string $level Ignore logging attempts at a level less the $level |
||
147 | * @return static |
||
148 | */ |
||
149 | 33 | public function setLogLevel($level) |
|
158 | |||
159 | /** |
||
160 | * @return $this |
||
161 | */ |
||
162 | public function lock() |
||
167 | |||
168 | /** |
||
169 | * @return $this |
||
170 | */ |
||
171 | 3 | public function gzipped() |
|
176 | |||
177 | /** |
||
178 | * @param callable $fnFormatter |
||
179 | * |
||
180 | * @return $this |
||
181 | */ |
||
182 | public function formatter(callable $fnFormatter) |
||
187 | |||
188 | /** |
||
189 | * Log messages to resource |
||
190 | * |
||
191 | * @param mixed $level The level of the log message |
||
192 | * @param string|object $message If an object is passed it must implement __toString() |
||
193 | * @param array $context Placeholders to be substituted in the message |
||
194 | * |
||
195 | * @return static |
||
196 | */ |
||
197 | 24 | public function log($level, $message, array $context = []) |
|
217 | |||
218 | /** |
||
219 | * @param $level |
||
220 | * @param $message |
||
221 | * @param array $context |
||
222 | * @return string |
||
223 | */ |
||
224 | 24 | protected function formatMessage($level, $message, array $context = []) |
|
234 | |||
235 | /** |
||
236 | * Write the content to the stream |
||
237 | * |
||
238 | * @param string $content |
||
239 | */ |
||
240 | 27 | public function write($content) |
|
253 | |||
254 | /** |
||
255 | * @return mixed|resource |
||
256 | * @throws \Exception |
||
257 | */ |
||
258 | 27 | protected function getResource() |
|
273 | |||
274 | /** |
||
275 | * @return string |
||
276 | */ |
||
277 | public function getLastLogEntry() |
||
281 | |||
282 | /** |
||
283 | * @return resource |
||
284 | */ |
||
285 | protected function openResource() |
||
293 | |||
294 | public function __destruct() |
||
301 | } |
||
302 | |||
303 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.