@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @var array |
| 17 | 17 | */ |
| 18 | - protected $config = [ |
|
| 18 | + protected $config = [ |
|
| 19 | 19 | 'save-path' => './logs', |
| 20 | 20 | 'save-zip-path' => './logs/zip', |
| 21 | 21 | 'save-pack-path' => './logs/dump', |
@@ -59,17 +59,17 @@ discard block |
||
| 59 | 59 | * @throws FileLoggerException |
| 60 | 60 | * @param array $config |
| 61 | 61 | */ |
| 62 | - public function __construct(array $config=[]) |
|
| 62 | + public function __construct(array $config = []) |
|
| 63 | 63 | { |
| 64 | 64 | $this->applyConfig($config); |
| 65 | 65 | $temp = tmpfile(); |
| 66 | 66 | if ($temp === false) { |
| 67 | - $this->tempname = $this->config['save-path'].'/log-'. microtime(true).'.tmp'; |
|
| 67 | + $this->tempname = $this->config['save-path'].'/log-'.microtime(true).'.tmp'; |
|
| 68 | 68 | $temp = fopen($this->tempname, 'w+'); |
| 69 | 69 | } |
| 70 | 70 | if ($temp !== false) { |
| 71 | 71 | $this->temp = $temp; |
| 72 | - }else{ |
|
| 72 | + } else { |
|
| 73 | 73 | throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file')); |
| 74 | 74 | } |
| 75 | 75 | $this->latest = $this->config['save-path'].'/'.$this->config['file-name']; |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | protected function packLogFile() |
| 79 | 79 | { |
| 80 | - $logFile= $this->latest; |
|
| 81 | - $path=preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'] .'/'.date('Y-m-d').'.zip'); |
|
| 80 | + $logFile = $this->latest; |
|
| 81 | + $path = preg_replace('/[\\\\]+/', '/', $this->config['save-zip-path'].'/'.date('Y-m-d').'.zip'); |
|
| 82 | 82 | $zip = new ZipArchive; |
| 83 | 83 | $res = $zip->open($path, ZipArchive::CREATE); |
| 84 | 84 | if ($res === true) { |
| 85 | - if ($zip->addFile($logFile, date('Y-m-d'). '-'. $zip->numFiles .'.log')) { |
|
| 85 | + if ($zip->addFile($logFile, date('Y-m-d').'-'.$zip->numFiles.'.log')) { |
|
| 86 | 86 | array_push($this->removeFiles, $logFile); |
| 87 | 87 | } |
| 88 | 88 | $it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->config['save-pack-path'])); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | $zip->close(); |
| 95 | 95 | } else { |
| 96 | 96 | if (is_file($logFile) && file_exists($logFile)) { |
| 97 | - rename($logFile, $this->config['save-path'] . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
| 97 | + rename($logFile, $this->config['save-path'].'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | */ |
| 118 | 118 | protected function checkSize():bool |
| 119 | 119 | { |
| 120 | - $logFile= $this->latest; |
|
| 120 | + $logFile = $this->latest; |
|
| 121 | 121 | if (file_exists($logFile)) { |
| 122 | 122 | if (filesize($logFile) > $this->config['max-file-size']) { |
| 123 | 123 | return true; |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | public function log($level, string $message, array $context = []) |
| 131 | 131 | { |
| 132 | - if (LogLevel::compare($level, $this->config['log-level']) >=0) { |
|
| 132 | + if (LogLevel::compare($level, $this->config['log-level']) >= 0) { |
|
| 133 | 133 | $replace = []; |
| 134 | 134 | $message = $this->interpolate($message, $context); |
| 135 | 135 | $replace['%level%'] = $level; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | { |
| 145 | 145 | $replace = []; |
| 146 | 146 | foreach ($context as $key => $val) { |
| 147 | - $replace['{' . $key . '}'] = $val; |
|
| 147 | + $replace['{'.$key.'}'] = $val; |
|
| 148 | 148 | } |
| 149 | 149 | return strtr($message, $replace); |
| 150 | 150 | } |
@@ -152,10 +152,10 @@ discard block |
||
| 152 | 152 | protected function rollLatest() |
| 153 | 153 | { |
| 154 | 154 | if (isset($this->latest)) { |
| 155 | - $size=ftell($this->temp); |
|
| 155 | + $size = ftell($this->temp); |
|
| 156 | 156 | fseek($this->temp, 0); |
| 157 | 157 | if ($size > 0) { |
| 158 | - $body=fread($this->temp, $size); |
|
| 158 | + $body = fread($this->temp, $size); |
|
| 159 | 159 | file_put_contents($this->latest, $body, FILE_APPEND); |
| 160 | 160 | } |
| 161 | 161 | fclose($this->temp); |
@@ -69,7 +69,7 @@ |
||
| 69 | 69 | } |
| 70 | 70 | if ($temp !== false) { |
| 71 | 71 | $this->temp = $temp; |
| 72 | - }else{ |
|
| 72 | + } else{ |
|
| 73 | 73 | throw new FileLoggerException(__CLASS__.':'.sprintf('cannot create log file')); |
| 74 | 74 | } |
| 75 | 75 | $this->latest = $this->config['save-path'].'/'.$this->config['file-name']; |