Skip to content

Commit

Permalink
Combine all log checking methods into LogCheckerTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobSanford committed Jul 11, 2023
1 parent 0cb1cc4 commit b0ad457
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 65 deletions.
60 changes: 59 additions & 1 deletion src/Logs/LogCheckerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,66 @@ private function logsHaveErrors(
return false;
}

protected function reportErrorsInLogs(DockworkerIO $io, $matches)
/**
* Gets the error strings to check for in logs.
*
* Calls the custom event handler dockworker-logs-errors-exceptions.
* Implementing functions should return an array of two arrays, the first
* containing error strings, and the second containing exception strings.
*
* Implementations wishing to describe the error strings in code should
* define an associative array with the key being the description and the
* value being the error string. Then, the array can be cast to a
* non-associative array using array_values().
*
* @return string[]
* An array of error strings and exception strings.
*/
public function getAllLogErrorStrings(): array
{
$errors = [
'error',
'fail',
'fatal',
'unable',
'unavailable',
'unrecognized',
'unresolved',
'unsuccessful',
'unsupported',
];
$exceptions = [];

$handlers = $this->getCustomEventHandlers('dockworker-logs-errors-exceptions');
foreach ($handlers as $handler) {
[$new_errors, $new_exceptions] = $handler();
$errors = array_merge(
$errors,
$new_errors
);
$exceptions = array_merge(
$exceptions,
$new_exceptions
);
}
return [
implode('|', $errors),
implode('|', $exceptions),
];
}

/**
* Reports errors found in logs.
*
* @param \Dockworker\IO\DockworkerIO $io
* The IO to use for input and output.
* @param string[] $matches
* An array of strings that matched as errors.
*/
protected function reportErrorsInLogs(
DockworkerIO $io,
array $matches
): void {
$io->error('Errors Found in Logs!');
$io->listing($matches);
}
Expand Down
62 changes: 0 additions & 62 deletions src/Logs/LogErrorStringsTrait.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/Robo/Plugin/Commands/LogCheckCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Dockworker\DockworkerCommands;
use Dockworker\IO\DockworkerIOTrait;
use Dockworker\Logs\LogCheckerTrait;
use Dockworker\Logs\LogErrorStringsTrait;

/**
* Provides commands to check a log file for errors.
Expand All @@ -17,7 +16,6 @@ class LogCheckCommands extends DockworkerCommands implements CustomEventAwareInt
use CustomEventAwareTrait;
use DockworkerIOTrait;
use LogCheckerTrait;
use LogErrorStringsTrait;

/**
* Checks a log file for errors.
Expand Down

0 comments on commit b0ad457

Please sign in to comment.