\d{2}-\w{3}-\d{4}\s\d{2}:\d{2}:\d{2}\s\w{3})\]/"; $fh = \Safe\fopen($filename, 'r'); $sum = 0; while(!feof($fh)) { $line = fgets($fh); $sum += \Safe\preg_match_all($regex, $line); } fclose($fh); return $sum; } catch (\Exception $e) { return 0; } } public function parse(string $content): Log { $log = parent::parse($content); $regex = "/\[(?\d{2}-\w{3}-\d{4}\s\d{2}:\d{2}:\d{2}\s\w{3})\]\s(?PHP|User)\s(?\w+):\s(?.*)/"; try { \Safe\preg_match($regex, $content, $matches); } catch (\Error $e) { \Safe\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) { $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)); if (count($extra) > 0) { $log->setExtra(\Safe\json_encode($extra, JSON_UNESCAPED_SLASHES)); } return $log; } }