mirror of
https://github.com/friendica/friendica
synced 2025-04-26 10:30:11 +00:00
Display structured logs in admin
Tries to parse log lines and to display info in a table. Additional JSON data is parsed and displayed clicking on a row. File reading and line parsing is handled in iterators, to avoid to keep too much data in memory. Search and filter should be trivial to add. Log file is read backward to display log events newest first. A "tail" functionality should be easy to implement.
This commit is contained in:
parent
4b3f1cbdb9
commit
9368f5445d
6 changed files with 361 additions and 25 deletions
81
src/Model/Log/ParsedLogIterator.php
Normal file
81
src/Model/Log/ParsedLogIterator.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2021, Friendica
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
namespace Friendica\Model\Log;
|
||||
|
||||
use \Friendica\Util\ReversedFileReader;
|
||||
use \Friendica\Object\Log\ParsedLog;
|
||||
|
||||
|
||||
/**
|
||||
* An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
|
||||
*
|
||||
* Uses `\Friendica\Util\ReversedFileReader` to fetch log lines
|
||||
* from newest to oldest
|
||||
*/
|
||||
class ParsedLogIterator implements \Iterator
|
||||
{
|
||||
public function __construct(string $filename, int $limit=0)
|
||||
{
|
||||
$this->reader = new ReversedFileReader($filename);
|
||||
$this->_value = null;
|
||||
$this->_limit = $limit;
|
||||
}
|
||||
|
||||
public function next()
|
||||
{
|
||||
$this->reader->next();
|
||||
if ($this->_limit > 0 && $this->reader->key() > $this->_limit) {
|
||||
$this->_value = null;
|
||||
return;
|
||||
}
|
||||
if ($this->reader->valid()) {
|
||||
$line = $this->reader->current();
|
||||
$this->_value = new ParsedLog($this->reader->key(), $line);
|
||||
} else {
|
||||
$this->_value = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function rewind()
|
||||
{
|
||||
$this->_value = null;
|
||||
$this->reader->rewind();
|
||||
$this->next();
|
||||
}
|
||||
|
||||
public function key()
|
||||
{
|
||||
return $this->reader->key();
|
||||
}
|
||||
|
||||
public function current()
|
||||
{
|
||||
return $this->_value;
|
||||
}
|
||||
|
||||
public function valid()
|
||||
{
|
||||
return ! is_null($this->_value);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue