Improve looks
This commit is contained in:
@ -16,7 +16,7 @@ class Log
|
||||
|
||||
public function getDate(): DateTimeInterface
|
||||
{
|
||||
return $this->dateTime;
|
||||
return $this->dateTime ?? new DateTimeImmutable();
|
||||
}
|
||||
public function getChannel(): string
|
||||
{
|
||||
@ -103,7 +103,9 @@ class Log
|
||||
|
||||
$regex = "/\[(?P<date>.*)\]\s(?<channel>\w*)\.(?<severity>\w*):\s(?<message>.*)\s[\[|\{](?<context>.*)[\]|\}]\s\[(?<extra>.*)\]/";
|
||||
preg_match($regex, $content, $matches);
|
||||
$log->setDate(DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $matches['date']));
|
||||
if (isset($matches['date'])) {
|
||||
$log->setDate(DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $matches['date']));
|
||||
}
|
||||
$log->setChannel($matches['channel']);
|
||||
$log->setSeverity($matches['severity']);
|
||||
$message = $matches['message'];
|
||||
|
@ -1,18 +1,23 @@
|
||||
<?php
|
||||
namespace ProVM\Logview\Log;
|
||||
|
||||
use Generator;
|
||||
use DateTimeInterface;
|
||||
use ProVM\Logview\Log;
|
||||
|
||||
class File
|
||||
{
|
||||
protected string $filename;
|
||||
protected DateTimeInterface $dateTime;
|
||||
protected string $content;
|
||||
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
public function getDate(): DateTimeInterface
|
||||
{
|
||||
return $this->dateTime;
|
||||
}
|
||||
public function getContent(): string
|
||||
{
|
||||
return $this->content;
|
||||
@ -23,6 +28,11 @@ class File
|
||||
$this->filename = $filename;
|
||||
return $this;
|
||||
}
|
||||
public function setDate(DateTimeInterface $dateTime): File
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
return $this;
|
||||
}
|
||||
public function setContent(string $content): File
|
||||
{
|
||||
$this->content = $content;
|
||||
|
Reference in New Issue
Block a user