Skip to content

Commit

Permalink
Add LogCheckCommands
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSanford committed Jul 11, 2023
1 parent 6709227 commit 1f28964
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Robo/Plugin/Commands/LogCheckCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Dockworker\Robo\Plugin\Commands;

use Dockworker\DockworkerCommands;
use Dockworker\IO\DockworkerIOTrait;
use Dockworker\Logs\LogCheckerTrait;
use Dockworker\Logs\LogErrorStringsTrait;

/**
* Provides commands to check a log file for errors.
*/
class LogCheckCommands extends DockworkerCommands
{
use DockworkerIOTrait;
use LogCheckerTrait;
use LogErrorStringsTrait;

/**
* Checks a log file for errors.
*
* @param string $file_path
* The path to the log file.
*
* @command logs:check-file
* @hidden
*/
public function setupGitHooks(string $file_path): void
{
[$errors_pattern, $exceptions_pattern] = $this->getAllLogErrorStrings();
$logs = file_get_contents($file_path);
$matched_error = '';
if (
$this->logsHaveErrors(
$logs,
$errors_pattern,
$exceptions_pattern,
$matched_error
)
) {
$this->dockworkerIO->error(
sprintf(
'Errors detected in logs. [%s] found in output.',
trim($matched_error)
)
);
exit(1);
}
else {
$this->dockworkerIO->writeln('No errors detected in logs.');
}
}
}

0 comments on commit 1f28964

Please sign in to comment.