feat(api): add 'show_timestamps' parameter to logs endpoints

This commit is contained in:
Yanluis Fermin
2025-07-30 21:32:11 -04:00
parent c239b8bbba
commit 0eb2ea86e8
4 changed files with 38 additions and 14 deletions
+8 -8
View File
@@ -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;