diff --git a/src/Model/Log/ParsedLogIterator.php b/src/Model/Log/ParsedLogIterator.php
index 15714454e..3e1832d96 100644
--- a/src/Model/Log/ParsedLogIterator.php
+++ b/src/Model/Log/ParsedLogIterator.php
@@ -18,11 +18,11 @@
* along with this program. If not, see .
*
*/
+
namespace Friendica\Model\Log;
-use \Friendica\Util\ReversedFileReader;
-use \Friendica\Object\Log\ParsedLog;
-
+use Friendica\Util\ReversedFileReader;
+use Friendica\Object\Log\ParsedLog;
/**
* An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
@@ -36,7 +36,7 @@ class ParsedLogIterator implements \Iterator
private $reader;
/** @var ParsedLog current iterator value*/
- private $value;
+ private $value;
/** @var int max number of lines to read */
private $limit;
@@ -54,19 +54,19 @@ class ParsedLogIterator implements \Iterator
* @param array $filter filters per column
* @param string $search string to search to filter lines
*/
- public function __construct(string $filename, int $limit=0, array $filters=[], string $search="")
+ public function __construct(string $filename, int $limit = 0, array $filters = [], string $search = "")
{
- $this->reader = new ReversedFileReader($filename);
- $this->value = null;
- $this->limit = $limit;
+ $this->reader = new ReversedFileReader($filename);
+ $this->value = null;
+ $this->limit = $limit;
$this->filters = $filters;
- $this->search = $search;
+ $this->search = $search;
}
/**
* Check if parsed log line match filters.
* Always match if no filters are set.
- *
+ *
* @param ParsedLog $parsedlog
* @return bool
*/
@@ -74,7 +74,7 @@ class ParsedLogIterator implements \Iterator
{
$match = true;
foreach ($this->filters as $filter => $filtervalue) {
- switch($filter) {
+ switch ($filter) {
case "level":
$match = $match && ($parsedlog->level == strtoupper($filtervalue));
break;
@@ -89,7 +89,7 @@ class ParsedLogIterator implements \Iterator
/**
* Check if parsed log line match search.
* Always match if no search query is set.
- *
+ *
* @param ParsedLog $parsedlog
* @return bool
*/
@@ -98,20 +98,20 @@ class ParsedLogIterator implements \Iterator
if ($this->search != "") {
return strstr($parsedlog->logline, $this->search) !== false;
}
- return True;
+ return true;
}
/**
* Read a line from reader and parse.
* Returns null if limit is reached or the reader is invalid.
- *
+ *
* @param ParsedLog $parsedlog
* @return ?ParsedLog
*/
private function read()
{
$this->reader->next();
- if ($this->limit > 0 && $this->reader->key() > $this->limit || !$this->reader->valid()) {
+ if ($this->limit > 0 && $this->reader->key() > $this->limit || !$this->reader->valid()) {
return null;
}
@@ -126,7 +126,7 @@ class ParsedLogIterator implements \Iterator
// if read() has not retuned none and
// the line don't match filters or search
// read the next line
- while(is_null($parsed) == false && !($this->filter($parsed) && $this->search($parsed))) {
+ while (is_null($parsed) == false && !($this->filter($parsed) && $this->search($parsed))) {
$parsed = $this->read();
}
$this->value = $parsed;
@@ -153,6 +153,4 @@ class ParsedLogIterator implements \Iterator
{
return ! is_null($this->value);
}
-
}
-
diff --git a/src/Module/Admin/Logs/View.php b/src/Module/Admin/Logs/View.php
index a51250727..26ad3a8b6 100644
--- a/src/Module/Admin/Logs/View.php
+++ b/src/Module/Admin/Logs/View.php
@@ -39,12 +39,12 @@ class View extends BaseAdmin
$t = Renderer::getMarkupTemplate('admin/logs/view.tpl');
DI::page()->registerFooterScript(Theme::getPathForFile('js/module/admin/logs/view.js'));
- $f = DI::config()->get('system', 'logfile');
- $data = null;
+ $f = DI::config()->get('system', 'logfile');
+ $data = null;
$error = null;
-
$search = $_GET['q'] ?? '';
+
$filters_valid_values = [
'level' => [
'',
@@ -58,10 +58,10 @@ class View extends BaseAdmin
'context' => ['', 'index', 'worker'],
];
$filters = [
- 'level' => $_GET['level'] ?? '',
+ 'level' => $_GET['level'] ?? '',
'context' => $_GET['context'] ?? '',
];
- foreach($filters as $k=>$v) {
+ foreach ($filters as $k => $v) {
if ($v == '' || !in_array($v, $filters_valid_values[$k])) {
unset($filters[$k]);
}
@@ -77,14 +77,14 @@ class View extends BaseAdmin
}
}
return Renderer::replaceMacros($t, [
- '$title' => DI::l10n()->t('Administration'),
- '$page' => DI::l10n()->t('View Logs'),
- '$data' => $data,
- '$q' => $search,
- '$filters' => $filters,
+ '$title' => DI::l10n()->t('Administration'),
+ '$page' => DI::l10n()->t('View Logs'),
+ '$data' => $data,
+ '$q' => $search,
+ '$filters' => $filters,
'$filtersvalues' => $filters_valid_values,
- '$error' => $error,
- '$logname' => DI::config()->get('system', 'logfile'),
+ '$error' => $error,
+ '$logname' => DI::config()->get('system', 'logfile'),
]);
}
}
diff --git a/src/Object/Log/ParsedLog.php b/src/Object/Log/ParsedLog.php
index f48ce400e..c33f4f950 100644
--- a/src/Object/Log/ParsedLog.php
+++ b/src/Object/Log/ParsedLog.php
@@ -18,6 +18,7 @@
* along with this program. If not, see .
*
*/
+
namespace Friendica\Object\Log;
/**
@@ -64,18 +65,22 @@ class ParsedLog
private function parse($logline)
{
list($logline, $jsonsource) = explode(' - ', $logline);
+
$jsondata = null;
+
if (strpos($logline, '{"') > 0) {
list($logline, $jsondata) = explode('{"', $logline, 2);
+
$jsondata = '{"' . $jsondata;
}
preg_match(self::REGEXP, $logline, $matches);
- $this->date = $matches[1];
+
+ $this->date = $matches[1];
$this->context = $matches[2];
- $this->level = $matches[3];
+ $this->level = $matches[3];
$this->message = $matches[4];
- $this->data = $jsondata;
- $this->source = $jsonsource;
+ $this->data = $jsondata;
+ $this->source = $jsonsource;
$this->try_fix_json();
$this->logline = $logline;
@@ -83,7 +88,7 @@ class ParsedLog
/**
* Fix message / data split
- *
+ *
* In log boundary between message and json data is not specified.
* If message contains '{' the parser thinks there starts the json data.
* This method try to parse the found json and if it fails, search for next '{'
@@ -112,12 +117,12 @@ class ParsedLog
*
* @return array
*/
- public function get_data() {
+ public function get_data()
+ {
$data = json_decode($this->data, true);
if ($data) {
- foreach($data as $k => $v) {
- $v = print_r($v, true);
- $data[$k] = $v;
+ foreach ($data as $k => $v) {
+ $data[$k] = print_r($v, true);
}
}
return $data;
@@ -128,7 +133,8 @@ class ParsedLog
*
* @return array
*/
- public function get_source() {
+ public function get_source()
+ {
return json_decode($this->source, true);
}
}
diff --git a/src/Util/ReversedFileReader.php b/src/Util/ReversedFileReader.php
index eeedc1a5c..c889b5f93 100644
--- a/src/Util/ReversedFileReader.php
+++ b/src/Util/ReversedFileReader.php
@@ -21,7 +21,6 @@
namespace Friendica\Util;
-
/**
* An iterator which returns lines from file in reversed order
*
@@ -29,87 +28,87 @@ namespace Friendica\Util;
*/
class ReversedFileReader implements \Iterator
{
- const BUFFER_SIZE = 4096;
- const SEPARATOR = "\n";
+ const BUFFER_SIZE = 4096;
+ const SEPARATOR = "\n";
- /** @var int */
- private $filesize;
+ /** @var int */
+ private $filesize;
- /** @var int */
- private $pos;
+ /** @var int */
+ private $pos;
- /** @var array */
- private $buffer;
+ /** @var array */
+ private $buffer;
- /** @var int */
- private $key;
+ /** @var int */
+ private $key;
- /** @var string */
- private $value;
+ /** @var string */
+ private $value;
- public function __construct($filename)
- {
- $this->_fh = fopen($filename, 'r');
+ public function __construct($filename)
+ {
+ $this->_fh = fopen($filename, 'r');
if (!$this->_fh) {
// this should use a custom exception.
throw \Exception("Unable to open $filename");
}
- $this->filesize = filesize($filename);
- $this->pos = -1;
- $this->buffer = null;
- $this->key = -1;
- $this->value = null;
- }
+ $this->filesize = filesize($filename);
+ $this->pos = -1;
+ $this->buffer = null;
+ $this->key = -1;
+ $this->value = null;
+ }
- public function _read($size)
- {
- $this->pos -= $size;
- fseek($this->_fh, $this->pos);
- return fread($this->_fh, $size);
- }
+ public function _read($size)
+ {
+ $this->pos -= $size;
+ fseek($this->_fh, $this->pos);
+ return fread($this->_fh, $size);
+ }
- public function _readline()
- {
- $buffer =& $this->buffer;
- while (true) {
- if ($this->pos == 0) {
- return array_pop($buffer);
- }
- if (count($buffer) > 1) {
- return array_pop($buffer);
- }
- $buffer = explode(self::SEPARATOR, $this->_read(self::BUFFER_SIZE) . $buffer[0]);
- }
- }
+ public function _readline()
+ {
+ $buffer = & $this->buffer;
+ while (true) {
+ if ($this->pos == 0) {
+ return array_pop($buffer);
+ }
+ if (count($buffer) > 1) {
+ return array_pop($buffer);
+ }
+ $buffer = explode(self::SEPARATOR, $this->_read(self::BUFFER_SIZE) . $buffer[0]);
+ }
+ }
- public function next()
- {
- ++$this->key;
- $this->value = $this->_readline();
- }
+ public function next()
+ {
+ ++$this->key;
+ $this->value = $this->_readline();
+ }
- public function rewind()
- {
- if ($this->filesize > 0) {
- $this->pos = $this->filesize;
- $this->value = null;
- $this->key = -1;
- $this->buffer = explode(self::SEPARATOR, $this->_read($this->filesize % self::BUFFER_SIZE ?: self::BUFFER_SIZE));
- $this->next();
- }
- }
+ public function rewind()
+ {
+ if ($this->filesize > 0) {
+ $this->pos = $this->filesize;
+ $this->value = null;
+ $this->key = -1;
+ $this->buffer = explode(self::SEPARATOR, $this->_read($this->filesize % self::BUFFER_SIZE ?: self::BUFFER_SIZE));
+ $this->next();
+ }
+ }
- public function key()
+ public function key()
{
return $this->key;
}
- public function current()
+ public function current()
{
return $this->value;
}
- public function valid()
+ public function valid()
{
return ! is_null($this->value);
}