Improve looks

This commit is contained in:
2023-02-14 22:50:35 -03:00
parent f8dbb1390e
commit 3718c1e0aa
7 changed files with 70 additions and 45 deletions

View File

@ -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'];

View File

@ -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;