@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * |
15 | 15 | * @var array |
16 | 16 | */ |
17 | - protected $config = [ |
|
17 | + protected $config = [ |
|
18 | 18 | 'save-path' => './logs', |
19 | 19 | 'save-zip-path' => './logs/zip', |
20 | 20 | 'save-pack-path' => './logs/dump', |
@@ -52,12 +52,12 @@ discard block |
||
52 | 52 | */ |
53 | 53 | protected $latest; |
54 | 54 | |
55 | - public function __construct(array $config=[]) |
|
55 | + public function __construct(array $config = []) |
|
56 | 56 | { |
57 | 57 | $this->applyConfig($config); |
58 | 58 | $temp = tmpfile(); |
59 | 59 | if ($temp === false) { |
60 | - $this->tempname = $this->config['save-path'].'/log-'. microtime(true).'.tmp'; |
|
60 | + $this->tempname = $this->config['save-path'].'/log-'.microtime(true).'.tmp'; |
|
61 | 61 | $temp = fopen($this->tempname, 'w+'); |
62 | 62 | } |
63 | 63 | $this->temp = $temp; |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | |
67 | 67 | protected function packLogFile() |
68 | 68 | { |
69 | - $logFile= $this->latest; |
|
70 | - $path=preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'] .'/'.date('Y-m-d').'.zip'); |
|
69 | + $logFile = $this->latest; |
|
70 | + $path = preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'].'/'.date('Y-m-d').'.zip'); |
|
71 | 71 | $zip = new ZipArchive; |
72 | 72 | $res = $zip->open($path, ZipArchive::CREATE); |
73 | 73 | if ($res === true) { |
74 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
74 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
75 | 75 | array_push($this->removeFiles, $logFile); |
76 | 76 | } |
77 | 77 | $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->config['save-pack-path'])); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $zip->close(); |
84 | 84 | } else { |
85 | 85 | if (is_file($logFile) && file_exists($logFile)) { |
86 | - rename($logFile, $this->config['save-path'] . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
86 | + rename($logFile, $this->config['save-path'].'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function checkSize():bool |
108 | 108 | { |
109 | - $logFile= $this->latest; |
|
109 | + $logFile = $this->latest; |
|
110 | 110 | if (file_exists($logFile)) { |
111 | 111 | if (filesize($logFile) > $this->config['max-file-size']) { |
112 | 112 | return true; |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | public function log($level, string $message, array $context = []) |
120 | 120 | { |
121 | - if (LogLevel::compare($level, $this->config['log-level']) >=0) { |
|
121 | + if (LogLevel::compare($level, $this->config['log-level']) >= 0) { |
|
122 | 122 | $replace = []; |
123 | 123 | $message = $this->interpolate($message, $context); |
124 | 124 | $replace['%level%'] = $level; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | { |
134 | 134 | $replace = []; |
135 | 135 | foreach ($context as $key => $val) { |
136 | - $replace['{' . $key . '}'] = $val; |
|
136 | + $replace['{'.$key.'}'] = $val; |
|
137 | 137 | } |
138 | 138 | return strtr($message, $replace); |
139 | 139 | } |
@@ -141,10 +141,10 @@ discard block |
||
141 | 141 | protected function rollLatest() |
142 | 142 | { |
143 | 143 | if (isset($this->latest)) { |
144 | - $size=ftell($this->temp); |
|
144 | + $size = ftell($this->temp); |
|
145 | 145 | fseek($this->temp, 0); |
146 | 146 | if ($size > 0) { |
147 | - $body=fread($this->temp, $size); |
|
147 | + $body = fread($this->temp, $size); |
|
148 | 148 | file_put_contents($this->latest, $body, FILE_APPEND); |
149 | 149 | } |
150 | 150 | fclose($this->temp); |