Skip to content

Commit

Permalink
Log reader now doesn't choke on negative lines
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavs-gutmanis committed Oct 4, 2018
1 parent 24e414d commit a70411c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Loggers/Readers/LineLogReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ public function getLastLines(int $numberOfLines = self::DEFAULT_NUMBER_OF_LINES)
if ($line) {
$lines[] = $line;
}
$currentKey--;
$this->file->seek($currentKey);

if (--$currentKey >= 0) {
$this->file->seek($currentKey);
}

if (\count($lines) >= $numberOfLines) {
break;
Expand Down
5 changes: 5 additions & 0 deletions tests/Loggers/LineLogReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public function testReadsLastThreeLines()
$this->assertCount(3, $this->logReader->getLastLines(3));
}

public function testAskingMoreLinesReturnsMaximum()
{
$this->assertCount(5, $this->logReader->getLastLines(20));
}

public function testDefaultParser()
{
list($lineA, $lineB, $lineC, $lineD) = $this->logReader->getLastLines(4);
Expand Down

0 comments on commit a70411c

Please sign in to comment.