Fix code formatting
This commit is contained in:
parent
5b9aeeeca9
commit
84fa668845
4 changed files with 102 additions and 99 deletions
|
@ -18,11 +18,11 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Model\Log;
|
namespace Friendica\Model\Log;
|
||||||
|
|
||||||
use \Friendica\Util\ReversedFileReader;
|
use Friendica\Util\ReversedFileReader;
|
||||||
use \Friendica\Object\Log\ParsedLog;
|
use Friendica\Object\Log\ParsedLog;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
|
* An iterator which returns `\Friendica\Objec\Log\ParsedLog` instances
|
||||||
|
@ -54,7 +54,7 @@ class ParsedLogIterator implements \Iterator
|
||||||
* @param array $filter filters per column
|
* @param array $filter filters per column
|
||||||
* @param string $search string to search to filter lines
|
* @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->reader = new ReversedFileReader($filename);
|
||||||
$this->value = null;
|
$this->value = null;
|
||||||
|
@ -74,7 +74,7 @@ class ParsedLogIterator implements \Iterator
|
||||||
{
|
{
|
||||||
$match = true;
|
$match = true;
|
||||||
foreach ($this->filters as $filter => $filtervalue) {
|
foreach ($this->filters as $filter => $filtervalue) {
|
||||||
switch($filter) {
|
switch ($filter) {
|
||||||
case "level":
|
case "level":
|
||||||
$match = $match && ($parsedlog->level == strtoupper($filtervalue));
|
$match = $match && ($parsedlog->level == strtoupper($filtervalue));
|
||||||
break;
|
break;
|
||||||
|
@ -98,7 +98,7 @@ class ParsedLogIterator implements \Iterator
|
||||||
if ($this->search != "") {
|
if ($this->search != "") {
|
||||||
return strstr($parsedlog->logline, $this->search) !== false;
|
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
|
// if read() has not retuned none and
|
||||||
// the line don't match filters or search
|
// the line don't match filters or search
|
||||||
// read the next line
|
// 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();
|
$parsed = $this->read();
|
||||||
}
|
}
|
||||||
$this->value = $parsed;
|
$this->value = $parsed;
|
||||||
|
@ -153,6 +153,4 @@ class ParsedLogIterator implements \Iterator
|
||||||
{
|
{
|
||||||
return ! is_null($this->value);
|
return ! is_null($this->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,8 @@ class View extends BaseAdmin
|
||||||
$data = null;
|
$data = null;
|
||||||
$error = null;
|
$error = null;
|
||||||
|
|
||||||
|
|
||||||
$search = $_GET['q'] ?? '';
|
$search = $_GET['q'] ?? '';
|
||||||
|
|
||||||
$filters_valid_values = [
|
$filters_valid_values = [
|
||||||
'level' => [
|
'level' => [
|
||||||
'',
|
'',
|
||||||
|
@ -61,7 +61,7 @@ class View extends BaseAdmin
|
||||||
'level' => $_GET['level'] ?? '',
|
'level' => $_GET['level'] ?? '',
|
||||||
'context' => $_GET['context'] ?? '',
|
'context' => $_GET['context'] ?? '',
|
||||||
];
|
];
|
||||||
foreach($filters as $k=>$v) {
|
foreach ($filters as $k => $v) {
|
||||||
if ($v == '' || !in_array($v, $filters_valid_values[$k])) {
|
if ($v == '' || !in_array($v, $filters_valid_values[$k])) {
|
||||||
unset($filters[$k]);
|
unset($filters[$k]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Friendica\Object\Log;
|
namespace Friendica\Object\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,12 +65,16 @@ class ParsedLog
|
||||||
private function parse($logline)
|
private function parse($logline)
|
||||||
{
|
{
|
||||||
list($logline, $jsonsource) = explode(' - ', $logline);
|
list($logline, $jsonsource) = explode(' - ', $logline);
|
||||||
|
|
||||||
$jsondata = null;
|
$jsondata = null;
|
||||||
|
|
||||||
if (strpos($logline, '{"') > 0) {
|
if (strpos($logline, '{"') > 0) {
|
||||||
list($logline, $jsondata) = explode('{"', $logline, 2);
|
list($logline, $jsondata) = explode('{"', $logline, 2);
|
||||||
|
|
||||||
$jsondata = '{"' . $jsondata;
|
$jsondata = '{"' . $jsondata;
|
||||||
}
|
}
|
||||||
preg_match(self::REGEXP, $logline, $matches);
|
preg_match(self::REGEXP, $logline, $matches);
|
||||||
|
|
||||||
$this->date = $matches[1];
|
$this->date = $matches[1];
|
||||||
$this->context = $matches[2];
|
$this->context = $matches[2];
|
||||||
$this->level = $matches[3];
|
$this->level = $matches[3];
|
||||||
|
@ -112,12 +117,12 @@ class ParsedLog
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_data() {
|
public function get_data()
|
||||||
|
{
|
||||||
$data = json_decode($this->data, true);
|
$data = json_decode($this->data, true);
|
||||||
if ($data) {
|
if ($data) {
|
||||||
foreach($data as $k => $v) {
|
foreach ($data as $k => $v) {
|
||||||
$v = print_r($v, true);
|
$data[$k] = print_r($v, true);
|
||||||
$data[$k] = $v;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
|
@ -128,7 +133,8 @@ class ParsedLog
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_source() {
|
public function get_source()
|
||||||
|
{
|
||||||
return json_decode($this->source, true);
|
return json_decode($this->source, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
namespace Friendica\Util;
|
namespace Friendica\Util;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An iterator which returns lines from file in reversed order
|
* An iterator which returns lines from file in reversed order
|
||||||
*
|
*
|
||||||
|
@ -70,7 +69,7 @@ class ReversedFileReader implements \Iterator
|
||||||
|
|
||||||
public function _readline()
|
public function _readline()
|
||||||
{
|
{
|
||||||
$buffer =& $this->buffer;
|
$buffer = & $this->buffer;
|
||||||
while (true) {
|
while (true) {
|
||||||
if ($this->pos == 0) {
|
if ($this->pos == 0) {
|
||||||
return array_pop($buffer);
|
return array_pop($buffer);
|
||||||
|
|
Loading…
Reference in a new issue