Changed logger so it avoids blank lines
This commit is contained in:
parent
d30dd3c05a
commit
ae12fdeaec
8 changed files with 14 additions and 7 deletions
|
@ -30,6 +30,7 @@ class GetLogJob extends AbstractJob implements IPagedJob
|
||||||
|
|
||||||
//load lines
|
//load lines
|
||||||
$lines = file_get_contents($path);
|
$lines = file_get_contents($path);
|
||||||
|
$lines = trim($lines);
|
||||||
$lines = explode(PHP_EOL, str_replace(["\r", "\n"], PHP_EOL, $lines));
|
$lines = explode(PHP_EOL, str_replace(["\r", "\n"], PHP_EOL, $lines));
|
||||||
$lines = array_reverse($lines);
|
$lines = array_reverse($lines);
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,19 @@ class Logger
|
||||||
if (empty(self::$buffer))
|
if (empty(self::$buffer))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
$sep = file_exists(self::$path)
|
||||||
|
? PHP_EOL
|
||||||
|
: '';
|
||||||
$fh = fopen(self::$path, 'ab');
|
$fh = fopen(self::$path, 'ab');
|
||||||
if (!$fh)
|
if (!$fh)
|
||||||
throw new SimpleException('Cannot write to log files');
|
throw new SimpleException('Cannot write to log files');
|
||||||
if (flock($fh, LOCK_EX))
|
if (flock($fh, LOCK_EX))
|
||||||
{
|
{
|
||||||
foreach (self::$buffer as $logEvent)
|
foreach (self::$buffer as $logEvent)
|
||||||
fwrite($fh, $logEvent->getFullText() . PHP_EOL);
|
{
|
||||||
|
fwrite($fh, $sep . $logEvent->getFullText());
|
||||||
|
$sep = PHP_EOL;
|
||||||
|
}
|
||||||
fflush($fh);
|
fflush($fh);
|
||||||
flock($fh, LOCK_UN);
|
flock($fh, LOCK_UN);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
|
|
|
@ -143,7 +143,7 @@ class AddPostJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$x = file_get_contents($logPath);
|
$x = file_get_contents($logPath);
|
||||||
$lines = array_filter(explode("\n", $x));
|
$lines = explode("\n", $x);
|
||||||
$this->assert->areEqual(1, count($lines));
|
$this->assert->areEqual(1, count($lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -300,7 +300,7 @@ class AddUserJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$x = file_get_contents($logPath);
|
$x = file_get_contents($logPath);
|
||||||
$lines = array_filter(explode("\n", $x));
|
$lines = explode("\n", $x);
|
||||||
$this->assert->areEqual(2, count($lines));
|
$this->assert->areEqual(2, count($lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ class EditPostJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$x = file_get_contents($logPath);
|
$x = file_get_contents($logPath);
|
||||||
$lines = array_filter(explode("\n", $x));
|
$lines = explode("\n", $x);
|
||||||
$this->assert->areEqual(3, count($lines));
|
$this->assert->areEqual(3, count($lines));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ class EditUserJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$x = file_get_contents($logPath);
|
$x = file_get_contents($logPath);
|
||||||
$lines = array_filter(explode("\n", $x));
|
$lines = explode("\n", $x);
|
||||||
$this->assert->areEqual(2, count($lines));
|
$this->assert->areEqual(2, count($lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ class FlagPostJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$logs = file_get_contents($logPath);
|
$logs = file_get_contents($logPath);
|
||||||
$logs = array_filter(explode("\n", $logs));
|
$logs = explode("\n", $logs);
|
||||||
$this->assert->areEqual(1, count($logs));
|
$this->assert->areEqual(1, count($logs));
|
||||||
$this->assert->isTrue(strpos($logs[0], 'flagged @' . $post->getId() . ' for moderator attention') !== false);
|
$this->assert->isTrue(strpos($logs[0], 'flagged @' . $post->getId() . ' for moderator attention') !== false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class FlagUserJobTest extends AbstractTest
|
||||||
|
|
||||||
$logPath = Logger::getLogPath();
|
$logPath = Logger::getLogPath();
|
||||||
$logs = file_get_contents($logPath);
|
$logs = file_get_contents($logPath);
|
||||||
$logs = array_filter(explode("\n", $logs));
|
$logs = explode("\n", $logs);
|
||||||
$this->assert->areEqual(1, count($logs));
|
$this->assert->areEqual(1, count($logs));
|
||||||
$this->assert->isTrue(strpos($logs[0], 'flagged +' . $user->getName() . ' for moderator attention') !== false);
|
$this->assert->isTrue(strpos($logs[0], 'flagged +' . $user->getName() . ' for moderator attention') !== false);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue