Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
# do not stop on another job's failure
fail-fast: false
matrix:
php-versions: ['7.4', '8.0']
php-versions: ['7.4', '8.0', '8.1']
databases: ['sqlite']
server-versions: ['master']

Expand Down
40 changes: 20 additions & 20 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions lib/Log/LogIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ public function __construct($handle, $dateFormat, $timezone) {
$this->next();
}

public function rewind() {
public function rewind(): void {
fseek($this->handle, 0, SEEK_END);
$this->position = ftell($this->handle) - self::CHUNK_SIZE;
$this->currentKey = 0;
}

/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function current() {
$entry = json_decode($this->lastLine, true);
if ($this->dateFormat !== \DateTime::ATOM) {
Expand All @@ -85,11 +89,11 @@ public function current() {
return $entry;
}

public function key() {
public function key(): int {
return $this->currentKey;
}

public function next() {
public function next(): void {
$this->currentLine = '';

// Loop through each character of the file looking for new lines
Expand Down Expand Up @@ -119,7 +123,7 @@ public function next() {
}
}

public function valid() {
public function valid(): bool {
if (!is_resource($this->handle)) {
return false;
}
Expand Down
27 changes: 12 additions & 15 deletions lib/Log/SearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,37 @@ class SearchFilter extends \FilterIterator {
*/
private $levels;

/**
* @param \Iterator $iterator
* @param string $query
*/
public function __construct(\Iterator $iterator, $query) {
public function __construct(\Iterator $iterator, string $query) {
parent::__construct($iterator);
$this->rewind();
$this->query = strtolower($query);
$this->levels = ['Debug', 'Info', 'Warning', 'Error', 'Fatal'];
}

private function formatLevel($level) {
private function formatLevel(int $level): string {
return isset($this->levels[$level]) ? $this->levels[$level] : 'Unknown';
}

public function accept() {
public function accept(): bool {
if (!$this->query) {
return true;
}
$value = $this->current();
return $this->inMessage($value['message'], $this->query)
|| stripos($value['app'], $this->query) !== false
|| stripos($value['reqId'], $this->query) !== false
|| stripos($value['user'], $this->query) !== false
|| stripos($value['url'], $this->query) !== false
|| stripos($this->formatLevel($value['level']), $this->query) !== false;
return $this->inMessage($value['message'] ?? '', $this->query)
|| stripos($value['app'] ?? '', $this->query) !== false
|| stripos($value['reqId'] ?? '', $this->query) !== false
|| stripos($value['user'] ?? '', $this->query) !== false
|| stripos($value['url'] ?? '', $this->query) !== false
|| stripos($this->formatLevel($value['level'] ?? -1), $this->query) !== false;
}

private function inMessage($message, $query) {
private function inMessage($message, string $query): bool {
if (is_string($message)) {
return stripos($message, $query) !== false;
} elseif (isset($message['Exception'])) {
return stripos($message['Exception'], $query) !== false
|| stripos($message['Message'], $query) !== false;
|| stripos($message['Message'] ?? '', $query) !== false;
}
return false;
}
}