Fix code formatting

This commit is contained in:
fabrixxm 2021-05-24 22:05:02 +02:00
parent 5b9aeeeca9
commit 84fa668845
4 changed files with 102 additions and 99 deletions

View File

@ -18,11 +18,11 @@
* 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;
use Friendica\Util\ReversedFileReader;
use Friendica\Object\Log\ParsedLog;
/**
* An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
@ -54,7 +54,7 @@ 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;
@ -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;
@ -98,7 +98,7 @@ class ParsedLogIterator implements \Iterator
if ($this->search != "") {
return strstr($parsedlog->logline, $this->search) !== false;
}
return True;
return true;
}
/**
@ -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);
}
}

View File

@ -43,8 +43,8 @@ class View extends BaseAdmin
$data = null;
$error = null;
$search = $_GET['q'] ?? '';
$filters_valid_values = [
'level' => [
'',
@ -61,7 +61,7 @@ class View extends BaseAdmin
'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]);
}

View File

@ -18,6 +18,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Object\Log;
/**
@ -64,12 +65,16 @@ 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->context = $matches[2];
$this->level = $matches[3];
@ -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);
}
}

View File

@ -21,7 +21,6 @@
namespace Friendica\Util;
/**
* An iterator which returns lines from file in reversed order
*
@ -70,7 +69,7 @@ class ReversedFileReader implements \Iterator
public function _readline()
{
$buffer =& $this->buffer;
$buffer = & $this->buffer;
while (true) {
if ($this->pos == 0) {
return array_pop($buffer);