@@ -10,13 +10,13 @@ |
||
| 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 | public function interpolate(string $message, array $context) |
| 16 | 16 | { |
| 17 | 17 | $replace = []; |
| 18 | 18 | foreach ($context as $key => $val) { |
| 19 | - $replace['{' . $key . '}'] = $val; |
|
| 19 | + $replace['{'.$key.'}'] = $val; |
|
| 20 | 20 | } |
| 21 | 21 | return strtr($message, $replace); |
| 22 | 22 | } |
@@ -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); |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | { |
| 167 | 167 | $replace = []; |
| 168 | 168 | foreach ($context as $key => $val) { |
| 169 | - $replace['{' . $key . '}'] = $val; |
|
| 169 | + $replace['{'.$key.'}'] = $val; |
|
| 170 | 170 | } |
| 171 | 171 | return strtr($message, $replace); |
| 172 | 172 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class Debug implements LoggerInterface, LoggerAwareInterface, DumpInterface, AttachInterface, ConfigInterface |
| 17 | 17 | { |
| 18 | - use LoggerTrait,LoggerAwareTrait,DumpTrait,AttachTrait,ConfigTrait; |
|
| 18 | + use LoggerTrait, LoggerAwareTrait, DumpTrait, AttachTrait, ConfigTrait; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | { |
| 44 | 44 | $replace = []; |
| 45 | 45 | foreach ($context as $key => $val) { |
| 46 | - $replace['{' . $key . '}'] = $val; |
|
| 46 | + $replace['{'.$key.'}'] = $val; |
|
| 47 | 47 | } |
| 48 | 48 | return strtr($message, $replace); |
| 49 | 49 | } |