Skip to content

Commit

Permalink
Make FileLogger not overwrite already-written bytes
Browse files Browse the repository at this point in the history
FileLogger was double-printing newlines and then overwriting the second newline with the first byte of the next line.  By fseeking to the very end and removing the extra newline, we can make the data read by 'tail -f' match the data that eventually gets written to the file.

H/T @flopex for finding the issue.
  • Loading branch information
hashbrowncipher committed May 21, 2015
1 parent 71b3419 commit 3929975
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Fluent/Logger/FileLogger.php
Expand Up @@ -88,7 +88,7 @@ public function post2(Entity $entity)
protected function postImpl(Entity $entity)
{
$packed = json_encode($entity->getData());
$data = $wbuffer = sprintf("%s\t%s\t%s\n",
$data = $wbuffer = sprintf("%s\t%s\t%s",
date(\DateTime::ISO8601, $entity->getTime()),
$entity->getTag(),
$packed . PHP_EOL
Expand All @@ -102,7 +102,7 @@ protected function postImpl(Entity $entity)
if (!flock($this->fp, LOCK_EX)) {
throw new \Exception('could not obtain LOCK_EX');
}
fseek($this->fp, -1, SEEK_END);
fseek($this->fp, 0, SEEK_END);

while ($written < $length) {
$nwrite = fwrite($this->fp, $wbuffer);
Expand Down

0 comments on commit 3929975

Please sign in to comment.