@@ -50,7 +50,7 @@ |
||
| 50 | 50 | { |
| 51 | 51 | $replace = []; |
| 52 | 52 | foreach ($context as $key => $val) { |
| 53 | - $replace['{' . $key . '}'] = $val; |
|
| 53 | + $replace['{'.$key.'}'] = $val; |
|
| 54 | 54 | } |
| 55 | 55 | return strtr($message, $replace); |
| 56 | 56 | } |
@@ -10,6 +10,6 @@ |
||
| 10 | 10 | { |
| 11 | 11 | public function log($level, string $message, array $context = []) |
| 12 | 12 | { |
| 13 | - print date('Y-m-d H:i:s') .' ' . $this->interpolate($message, $context) . PHP_EOL; |
|
| 13 | + print date('Y-m-d H:i:s').' '.$this->interpolate($message, $context).PHP_EOL; |
|
| 14 | 14 | } |
| 15 | 15 | } |
@@ -46,12 +46,12 @@ discard block |
||
| 46 | 46 | * @throws FileLoggerException |
| 47 | 47 | * @param array $config |
| 48 | 48 | */ |
| 49 | - public function __construct(array $config=[]) |
|
| 49 | + public function __construct(array $config = []) |
|
| 50 | 50 | { |
| 51 | 51 | $this->applyConfig($config); |
| 52 | 52 | $temp = tmpfile(); |
| 53 | 53 | if ($temp === false) { |
| 54 | - $this->tempname = $this->getConfig('save-path').'/log-'. microtime(true).'.tmp'; |
|
| 54 | + $this->tempname = $this->getConfig('save-path').'/log-'.microtime(true).'.tmp'; |
|
| 55 | 55 | $temp = fopen($this->tempname, 'w+'); |
| 56 | 56 | } |
| 57 | 57 | if ($temp !== false) { |
@@ -77,12 +77,12 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | protected function packLogFile() |
| 79 | 79 | { |
| 80 | - $logFile= $this->latest; |
|
| 81 | - $path=preg_replace('/[\\\\]+/', '/', $this->getConfig('save-zip-path') .'/'.date('Y-m-d').'.zip'); |
|
| 80 | + $logFile = $this->latest; |
|
| 81 | + $path = preg_replace('/[\\\\]+/', '/', $this->getConfig('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->getConfig('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->getConfig('save-path') . '/' . date('Y-m-d'). '-'. substr(md5_file($logFile), 0, 8).'.log'); |
|
| 97 | + rename($logFile, $this->getConfig('save-path').'/'.date('Y-m-d').'-'.substr(md5_file($logFile), 0, 8).'.log'); |
|
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -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->getConfig('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->getConfig('log-level')) >=0) { |
|
| 121 | + if (LogLevel::compare($level, $this->getConfig('log-level')) >= 0) { |
|
| 122 | 122 | $replace = []; |
| 123 | 123 | $message = $this->interpolate($message, $context); |
| 124 | 124 | $replace['%level%'] = $level; |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | protected function rollLatest() |
| 132 | 132 | { |
| 133 | 133 | if (isset($this->latest)) { |
| 134 | - $size=ftell($this->temp); |
|
| 134 | + $size = ftell($this->temp); |
|
| 135 | 135 | fseek($this->temp, 0); |
| 136 | 136 | if ($size > 0) { |
| 137 | - $body=fread($this->temp, $size); |
|
| 137 | + $body = fread($this->temp, $size); |
|
| 138 | 138 | file_put_contents($this->latest, $body, FILE_APPEND); |
| 139 | 139 | } |
| 140 | 140 | fclose($this->temp); |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | } |
| 21 | 21 | public function getConfig(string $name) { |
| 22 | 22 | $defaultConfig = $this->getDefaultConfig(); |
| 23 | - return $this->config[$name] ?? $defaultConfig[$name];; |
|
| 23 | + return $this->config[$name] ?? $defaultConfig[$name]; ; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | abstract public function getDefaultConfig():array; |