Skip to content

Commit

Permalink
Merge pull request #283 from ARCANEDEV/patch-1
Browse files Browse the repository at this point in the history
[5.0] Fixing the log checker
  • Loading branch information
arcanedev-maroc authored Sep 12, 2019
2 parents bfb20e3 + 1eaf293 commit 180eaef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

php:
- 7.2
- 7.3
Expand Down
6 changes: 4 additions & 2 deletions src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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);
}
}
}
14 changes: 7 additions & 7 deletions src/Utilities/LogChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,17 @@ private function checkLogFile($path)
$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->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($filename)) {
$this->status = $status = false;
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 laravel-YYYY-MM-DD.log.";
"The log file [$filename] has an invalid date, the format must be like {$pattern}.";
}

$this->files[$filename] = compact('filename', 'status', 'message', 'path');
Expand All @@ -299,13 +300,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 = $this->filesystem->getPattern();

return ((bool) preg_match("/{$pattern}/", $file, $matches)) === false;
}
}

0 comments on commit 180eaef

Please sign in to comment.