我使用monolog库记录到文本文件.. 它按日期排序:
[2016-10-19 03:39:05] name.WARNING: Foo [] []
[2016-10-19 03:40:05] name.ERROR: Bar [] []
[2016-10-19 03:41:32] name.WARNING: Foo [] []
[2016-10-19 03:42:18] name.ERROR: Bar [] []
[2016-10-19 03:43:42] name.WARNING: Foo [] []
我想颠倒这个顺序,以便最近将是最顶级的..
有没有一种简单的方法可以用monolog(也许是一些隐藏的设置?)
答案 0 :(得分:0)
This code will read your log file and display the last lines $qtd_rows in reverse
$file = 'error.log';
$handle = fopen($file, "r");
$linecounter = $qtd_rows;
$pos = -2;
$beginning = false;
$this->lines = array();
while ($linecounter > 0) {
$t = " ";
while ($t != "\n") {
if(fseek($handle, $pos, SEEK_END) == -1) {
$beginning = true; break;
}`enter code here`
$t = fgetc($handle);
$pos --;
}
if($beginning) rewind($handle);
$line = fgets($handle);
$lines[$lines-(--$linecounter)-1] = $line;
if($beginning) break;
}
fclose ($handle);
foreach($lines as $key => $value) {
echo $value;
};