44 lines
1.2 KiB
PHP
44 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace LogDb\Client;
|
|
|
|
use DateTimeInterface;
|
|
use JsonSerializable;
|
|
|
|
class LogEvent implements JsonSerializable
|
|
{
|
|
public function __construct(
|
|
public readonly string $brief,
|
|
public readonly ?string $detail = null,
|
|
public readonly ?string $level = null,
|
|
public readonly ?string $scope = null,
|
|
public readonly ?string $source = null,
|
|
public readonly ?string $origin = null,
|
|
public readonly array $context = [],
|
|
public readonly ?DateTimeInterface $date = null,
|
|
)
|
|
{
|
|
}
|
|
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
$context = $this->context;
|
|
$scope = $this->scope;
|
|
if (isset($context['_scope'])) {
|
|
$scope = $context['_scope'];
|
|
unset($context['_scope']);
|
|
}
|
|
return [
|
|
'brief' => $this->brief,
|
|
'detail' => $this->detail,
|
|
'level' => $this->level,
|
|
'scope' => $scope,
|
|
'source' => $this->source,
|
|
'origin' => $this->origin,
|
|
'context' => $context,
|
|
'date' => $this->date?->format('Y-m-d H:i:s P'),
|
|
];
|
|
}
|
|
}
|
|
|