2 Commits

2 changed files with 10 additions and 3 deletions

View File

@@ -41,9 +41,10 @@ class LogDbClient
case 'http': case 'http':
$url = $this->server . "/api/logdb/v1/create-event"; $url = $this->server . "/api/logdb/v1/create-event";
if (!str_starts_with($url, "http")) $url = "http://{$url}"; if (!str_starts_with($url, "http")) $url = "http://{$url}";
$this->sendHttp(json_encode($event), $url); $this->sendHttp(json_encode($events), $url);
break; break;
case 'udp': case 'udp':
// TODO set batch id, the server is unaware that this is a batch.
foreach ($events as $event) { foreach ($events as $event) {
if ($event instanceof LogEvent) { if ($event instanceof LogEvent) {
[$ip,$port] = explode(":", $this->server, 2); [$ip,$port] = explode(":", $this->server, 2);

View File

@@ -22,14 +22,20 @@ class LogEvent implements JsonSerializable
public function jsonSerialize(): mixed public function jsonSerialize(): mixed
{ {
$context = $this->context;
$scope = $this->scope;
if (isset($context['_scope'])) {
$scope = $context['_scope'];
unset($context['_scope']);
}
return [ return [
'brief' => $this->brief, 'brief' => $this->brief,
'detail' => $this->detail, 'detail' => $this->detail,
'level' => $this->level, 'level' => $this->level,
'scope' => $this->scope, 'scope' => $scope,
'source' => $this->source, 'source' => $this->source,
'origin' => $this->origin, 'origin' => $this->origin,
'context' => $this->context, 'context' => $context,
'date' => $this->date?->format('Y-m-d H:i:s P'), 'date' => $this->date?->format('Y-m-d H:i:s P'),
]; ];
} }