Skip to content

Commit

Permalink
Merge pull request #289 from ARCANEDEV/patch-7
Browse files Browse the repository at this point in the history
[4.2] Fixing the log checker, compact() error and other stuff
  • Loading branch information
arcanedev-maroc authored Sep 12, 2019
2 parents e224421 + 9f00ae1 commit e200012
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:
- 5.6
- 7.0
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"license": "MIT",
"require": {
"php": ">=5.6",
"ext-json": "*",
"psr/log": "~1.0",
"arcanedev/support": "~3.20"
},
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions src/Commands/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
36 changes: 17 additions & 19 deletions src/Utilities/LogChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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;
}
}

0 comments on commit e200012

Please sign in to comment.