<?php
declare(strict_types=1);
namespace FlexApp\DTO;
use DateTime;
use DateTimeInterface;
use JsonSerializable;
use Monolog\Logger;
use Monolog\Logger as MessageLevel;
class LogMessageDto implements JsonSerializable
{
private string $app;
private DateTimeInterface $createdAt;
private string $message;
private string $messageLevel;
private string $job;
public function __construct(
string $message,
string $messageLevel,
string $job,
string $app
) {
$this->setApplication($app);
$this->setMessage($message);
$this->setMessageLevel($messageLevel);
$this->setJob($job);
$this->createdAt = new DateTime();
}
public function getApplication(): string
{
return $this->app;
}
public function setApplication(string $app): void
{
$this->app = $app;
}
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function getMessage(): string
{
return $this->message;
}
public function setMessage(string $message): void
{
$this->message = $message;
}
public function getMessageLevel(): string
{
return $this->messageLevel;
}
public function setMessageLevel(string $messageLevel): void
{
$normalized = strtoupper($messageLevel);
if (!in_array($normalized, Logger::getLevels(), true)) {
$messageLevel = mb_strtolower(Logger::getLevelName(MessageLevel::INFO));
}
$this->messageLevel = $messageLevel;
}
public function jsonSerialize(): array
{
return [
'app' => $this->app,
'job' => $this->job,
'message' => $this->message,
'messageLevel' => $this->messageLevel,
'createdAt' => $this->createdAt->format(DateTimeInterface::ATOM),
];
}
public function getJob(): string
{
return $this->job;
}
public function setJob(string $job): void
{
$this->job = $job;
}
}