From 9f00ae13d2aff00e6389d9cfceb84860f5fe476d Mon Sep 17 00:00:00 2001 From: ARCANEDEV Date: Thu, 12 Sep 2019 18:31:27 +0100 Subject: [PATCH] Fixing the log checker, compact() error and other stuff --- .gitattributes | 2 +- .travis.yml | 2 -- composer.json | 1 + phpunit.xml => phpunit.xml.dist | 0 src/Commands/CheckCommand.php | 6 ++-- src/Http/Controllers/LogViewerController.php | 2 +- src/Utilities/LogChecker.php | 36 +++++++++----------- 7 files changed, 24 insertions(+), 25 deletions(-) rename phpunit.xml => phpunit.xml.dist (100%) diff --git a/.gitattributes b/.gitattributes index 31c64b49..907b2393 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,4 +11,4 @@ .scrutinizer.yml export-ignore .travis.yml export-ignore CONTRIBUTING.md export-ignore -phpunit.xml export-ignore +phpunit.xml.dist export-ignore diff --git a/.travis.yml b/.travis.yml index 378d088e..7c54f833 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - php: - 5.6 - 7.0 diff --git a/composer.json b/composer.json index 753d5346..6fa4c73e 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "license": "MIT", "require": { "php": ">=5.6", + "ext-json": "*", "psr/log": "~1.0", "arcanedev/support": "~3.20" }, diff --git a/phpunit.xml b/phpunit.xml.dist similarity index 100% rename from phpunit.xml rename to phpunit.xml.dist diff --git a/src/Commands/CheckCommand.php b/src/Commands/CheckCommand.php index 47217b0a..21a269fe 100644 --- a/src/Commands/CheckCommand.php +++ b/src/Commands/CheckCommand.php @@ -81,7 +81,9 @@ private function displayMessages() $rows[] = [$file, $message]; } - $this->frame('LogViewer messages'); - $this->table(['File', 'Message'], $rows); + if ( ! empty($rows)) { + $this->frame('LogViewer messages'); + $this->table(['File', 'Message'], $rows); + } } } diff --git a/src/Http/Controllers/LogViewerController.php b/src/Http/Controllers/LogViewerController.php index c8073d0c..7b59afe1 100644 --- a/src/Http/Controllers/LogViewerController.php +++ b/src/Http/Controllers/LogViewerController.php @@ -69,7 +69,7 @@ public function listLogs(Request $request) $headers = $stats->header(); $rows = $this->paginate($stats->rows(), $request); - return $this->view('logs', compact('headers', 'rows', 'footer')); + return $this->view('logs', compact('headers', 'rows')); } /** diff --git a/src/Utilities/LogChecker.php b/src/Utilities/LogChecker.php index 9c77c86b..ba907101 100644 --- a/src/Utilities/LogChecker.php +++ b/src/Utilities/LogChecker.php @@ -260,22 +260,23 @@ private function checkLogFiles() */ private function checkLogFile($path) { - $status = true; - $file = basename($path); - $message = "The log file [$file] is valid."; - - if ($this->isSingleLogFile($file)) { - $this->status = $status = false; - $this->messages['files'][$file] = $message = - "You have a single log file in your application, you should split the [$file] into seperate log files."; + $status = true; + $filename = basename($path); + $message = "The log file [$filename] is valid."; + $pattern = $this->filesystem->getPattern(); + + if ($this->isSingleLogFile($filename)) { + $this->status = $status = false; + $this->messages['files'][$filename] = $message = + "You have a single log file in your application, you should split the [$filename] into separate log files."; } - elseif ($this->isInvalidLogDate($file)) { - $this->status = $status = false; - $this->messages['files'][$file] = $message = - "The log file [$file] has an invalid date, the format must be like laravel-YYYY-MM-DD.log."; + elseif ($this->isInvalidLogPattern($filename, $pattern)) { + $this->status = $status = false; + $this->messages['files'][$filename] = $message = + "The log file [$filename] has an invalid date, the format must be like {$pattern}."; } - $this->files[$file] = compact('filename', 'status', 'message', 'path'); + $this->files[$filename] = compact('filename', 'status', 'message', 'path'); } /** @@ -294,15 +295,12 @@ private function isSingleLogFile($file) * Check the date of the log file. * * @param string $file + * @param string $pattern * * @return bool */ - private function isInvalidLogDate($file) + private function isInvalidLogPattern($file, $pattern) { - $pattern = '/laravel-(\d){4}-(\d){2}-(\d){2}.log/'; - - if ((bool) preg_match($pattern, $file, $matches) === false) return true; - - return false; + return ((bool) preg_match("/{$pattern}/", $file, $matches)) === false; } }