Colors moved to template files, and namespace cleanups
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
<?php
|
||||
namespace ProVM\Logview\Parser;
|
||||
|
||||
use Error;
|
||||
use Exception;
|
||||
use Safe\DateTimeImmutable;
|
||||
use function Safe\{fopen, preg_match_all, preg_match, error_log, json_encode};
|
||||
use ProVM\Common\Define\Log;
|
||||
use ProVM\Common\Implement\Parser;
|
||||
|
||||
@ -11,15 +14,15 @@ class PHPDefault extends Parser
|
||||
{
|
||||
try {
|
||||
$regex = "/\[(?<date>\d{2}-\w{3}-\d{4}\s\d{2}:\d{2}:\d{2}\s\w{3})\]/";
|
||||
$fh = \Safe\fopen($filename, 'r');
|
||||
$fh = fopen($filename, 'r');
|
||||
$sum = 0;
|
||||
while(!feof($fh)) {
|
||||
$line = fgets($fh);
|
||||
$sum += \Safe\preg_match_all($regex, $line);
|
||||
$sum += preg_match_all($regex, $line);
|
||||
}
|
||||
fclose($fh);
|
||||
return $sum;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -28,25 +31,25 @@ class PHPDefault extends Parser
|
||||
$log = parent::parse($content);
|
||||
$regex = "/\[(?<date>\d{2}-\w{3}-\d{4}\s\d{2}:\d{2}:\d{2}\s\w{3})\]\s(?<level>PHP|User)\s(?<severity>\w+):\s(?<message>.*)/";
|
||||
try {
|
||||
\Safe\preg_match($regex, $content, $matches);
|
||||
} catch (\Error $e) {
|
||||
\Safe\error_log($e . PHP_EOL, 3, '/logs/debug.log');
|
||||
preg_match($regex, $content, $matches);
|
||||
} catch (Error $e) {
|
||||
error_log($e . PHP_EOL, 3, '/logs/debug.log');
|
||||
return $log;
|
||||
}
|
||||
|
||||
$extra = [];
|
||||
try {
|
||||
$log->setDate(DateTimeImmutable::createFromFormat('d-M-Y H:i:s e', $matches['date']));
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$log->setDate(new DateTimeImmutable());
|
||||
$extra['date'] = $matches['date'];
|
||||
}
|
||||
$log->setChannel('');
|
||||
$log->setSeverity($matches['severity']);
|
||||
$log->setMessage($matches['message']);
|
||||
$log->setContext(\Safe\json_encode(['level' => $matches['level']], JSON_UNESCAPED_SLASHES));
|
||||
$log->setContext(json_encode(['level' => $matches['level']], JSON_UNESCAPED_SLASHES));
|
||||
if (count($extra) > 0) {
|
||||
$log->setExtra(\Safe\json_encode($extra, JSON_UNESCAPED_SLASHES));
|
||||
$log->setExtra(json_encode($extra, JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
|
||||
return $log;
|
||||
|
Reference in New Issue
Block a user