Changed logger so it avoids blank lines

This commit is contained in:
Marcin Kurczewski 2014-05-13 14:03:27 +02:00
parent d30dd3c05a
commit ae12fdeaec
8 changed files with 14 additions and 7 deletions

View file

@ -30,6 +30,7 @@ class GetLogJob extends AbstractJob implements IPagedJob
//load lines
$lines = file_get_contents($path);
$lines = trim($lines);
$lines = explode(PHP_EOL, str_replace(["\r", "\n"], PHP_EOL, $lines));
$lines = array_reverse($lines);

View file

@ -27,13 +27,19 @@ class Logger
if (empty(self::$buffer))
return;
$sep = file_exists(self::$path)
? PHP_EOL
: '';
$fh = fopen(self::$path, 'ab');
if (!$fh)
throw new SimpleException('Cannot write to log files');
if (flock($fh, LOCK_EX))
{
foreach (self::$buffer as $logEvent)
fwrite($fh, $logEvent->getFullText() . PHP_EOL);
{
fwrite($fh, $sep . $logEvent->getFullText());
$sep = PHP_EOL;
}
fflush($fh);
flock($fh, LOCK_UN);
fclose($fh);

View file

@ -143,7 +143,7 @@ class AddPostJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$x = file_get_contents($logPath);
$lines = array_filter(explode("\n", $x));
$lines = explode("\n", $x);
$this->assert->areEqual(1, count($lines));
}

View file

@ -300,7 +300,7 @@ class AddUserJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$x = file_get_contents($logPath);
$lines = array_filter(explode("\n", $x));
$lines = explode("\n", $x);
$this->assert->areEqual(2, count($lines));
}
}

View file

@ -54,7 +54,7 @@ class EditPostJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$x = file_get_contents($logPath);
$lines = array_filter(explode("\n", $x));
$lines = explode("\n", $x);
$this->assert->areEqual(3, count($lines));
}
}

View file

@ -52,7 +52,7 @@ class EditUserJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$x = file_get_contents($logPath);
$lines = array_filter(explode("\n", $x));
$lines = explode("\n", $x);
$this->assert->areEqual(2, count($lines));
}

View file

@ -17,7 +17,7 @@ class FlagPostJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$logs = file_get_contents($logPath);
$logs = array_filter(explode("\n", $logs));
$logs = explode("\n", $logs);
$this->assert->areEqual(1, count($logs));
$this->assert->isTrue(strpos($logs[0], 'flagged @' . $post->getId() . ' for moderator attention') !== false);
}

View file

@ -17,7 +17,7 @@ class FlagUserJobTest extends AbstractTest
$logPath = Logger::getLogPath();
$logs = file_get_contents($logPath);
$logs = array_filter(explode("\n", $logs));
$logs = explode("\n", $logs);
$this->assert->areEqual(1, count($logs));
$this->assert->isTrue(strpos($logs[0], 'flagged +' . $user->getName() . ' for moderator attention') !== false);
}