feat(api): add 'show_timestamps' parameter to logs endpoints
This commit is contained in:
parent
c239b8bbba
commit
0eb2ea86e8
4 changed files with 38 additions and 14 deletions
|
|
@ -1553,6 +1553,13 @@ public function application_by_uuid(Request $request)
|
|||
default: 100,
|
||||
)
|
||||
),
|
||||
new OA\Parameter(
|
||||
name: 'show_timestamps',
|
||||
in: 'query',
|
||||
description: 'Show timestamps in the logs.',
|
||||
required: false,
|
||||
schema: new OA\Schema(type: 'boolean', default: false),
|
||||
),
|
||||
],
|
||||
responses: [
|
||||
new OA\Response(
|
||||
|
|
@ -1616,8 +1623,9 @@ public function logs_by_uuid(Request $request)
|
|||
], 400);
|
||||
}
|
||||
|
||||
$lines = $request->query->get('lines', 100) ?: 100;
|
||||
$logs = getContainerLogs($application->destination->server, $container['ID'], $lines);
|
||||
$lines = $request->query->get('lines', 100);
|
||||
$showTimestamps = $request->query->get('show_timestamps', false);
|
||||
$logs = getContainerLogs($application->destination->server, $container['ID'], $lines, $showTimestamps);
|
||||
|
||||
return response()->json([
|
||||
'logs' => $logs,
|
||||
|
|
|
|||
|
|
@ -1566,6 +1566,13 @@ public function create_database(Request $request, NewDatabaseTypes $type)
|
|||
default: 100,
|
||||
)
|
||||
),
|
||||
new OA\Parameter(
|
||||
name: 'show_timestamps',
|
||||
in: 'query',
|
||||
description: 'Show timestamps in the logs.',
|
||||
required: false,
|
||||
schema: new OA\Schema(type: 'boolean', default: false),
|
||||
),
|
||||
],
|
||||
responses: [
|
||||
new OA\Response(
|
||||
|
|
@ -1629,8 +1636,9 @@ public function logs_by_uuid(Request $request)
|
|||
], 400);
|
||||
}
|
||||
|
||||
$lines = $request->query->get('lines', 100) ?: 100;
|
||||
$logs = getContainerLogs($database->destination->server, $container['ID'], $lines);
|
||||
$lines = $request->query->get('lines', 100);
|
||||
$showTimestamps = $request->query->get('show_timestamps', false);
|
||||
$logs = getContainerLogs($database->destination->server, $container['ID'], $lines, $showTimestamps);
|
||||
|
||||
return response()->json([
|
||||
'logs' => $logs,
|
||||
|
|
|
|||
|
|
@ -486,6 +486,13 @@ public function service_by_uuid(Request $request)
|
|||
default: 100,
|
||||
)
|
||||
),
|
||||
new OA\Parameter(
|
||||
name: 'show_timestamps',
|
||||
in: 'query',
|
||||
description: 'Show timestamps in the logs.',
|
||||
required: false,
|
||||
schema: new OA\Schema(type: 'boolean', default: false),
|
||||
),
|
||||
],
|
||||
responses: [
|
||||
new OA\Response(
|
||||
|
|
@ -551,8 +558,9 @@ public function logs_by_uuid(Request $request)
|
|||
], 400);
|
||||
}
|
||||
|
||||
$lines = $request->query->get('lines', 100) ?: 100;
|
||||
$logs = getContainerLogs($service->destination->server, $container['ID'], $lines);
|
||||
$lines = $request->query->get('lines', 100);
|
||||
$showTimestamps = $request->query->get('show_timestamps', false);
|
||||
$logs = getContainerLogs($service->destination->server, $container['ID'], $lines, $showTimestamps);
|
||||
|
||||
return response()->json([
|
||||
'logs' => $logs,
|
||||
|
|
|
|||
|
|
@ -1115,18 +1115,18 @@ function validateComposeFile(string $compose, int $server_id): string|Throwable
|
|||
}
|
||||
}
|
||||
|
||||
function getContainerLogs(Server $server, string $container_id, int $lines = 100): string
|
||||
function getContainerLogs(Server $server, string $container_id, int $lines = 100, bool $showTimestamps = false): string
|
||||
{
|
||||
$command = "docker logs -n {$lines} {$container_id}";
|
||||
if ($server->isSwarm()) {
|
||||
$output = instant_remote_process([
|
||||
"docker service logs -n {$lines} {$container_id}",
|
||||
], $server);
|
||||
} else {
|
||||
$output = instant_remote_process([
|
||||
"docker logs -n {$lines} {$container_id}",
|
||||
], $server);
|
||||
$command = "docker service logs -n {$lines} {$container_id}";
|
||||
}
|
||||
|
||||
if ($showTimestamps) {
|
||||
$command .= ' --timestamps';
|
||||
}
|
||||
|
||||
$output = instant_remote_process([$command], $server);
|
||||
$output .= removeAnsiColors($output);
|
||||
|
||||
return $output;
|
||||
|
|
|
|||
Loading…
Reference in a new issue