feat(logs): Add dropdown to download displayed or all logs

Users can now choose between downloading only the currently displayed
logs or fetching and downloading all available logs from the container.

Changes:
- Add downloadAllLogs() method that fetches all logs without limit
- Replace download button with dropdown menu
- Options: "Download displayed logs" and "Download all logs"

Addresses #7803
This commit is contained in:
Claude
2025-12-29 17:59:23 +00:00
parent b484c0cc25
commit bbb2aa9ad4
2 changed files with 87 additions and 8 deletions

View File

@@ -188,6 +188,50 @@ class GetLogs extends Component
return sanitizeLogsForExport($this->outputs);
}
public function downloadAllLogs(): string
{
if (! $this->server->isFunctional() || ! $this->container) {
return '';
}
if ($this->showTimeStamps) {
if ($this->server->isSwarm()) {
$command = "docker service logs -t {$this->container}";
} else {
$command = "docker logs -t {$this->container}";
}
} else {
if ($this->server->isSwarm()) {
$command = "docker service logs {$this->container}";
} else {
$command = "docker logs {$this->container}";
}
}
if ($this->server->isNonRoot()) {
$command = parseCommandsByLineForSudo(collect($command), $this->server);
$command = $command[0];
}
$sshCommand = SshMultiplexingHelper::generateSshCommand($this->server, $command);
$allLogs = '';
Process::run($sshCommand, function (string $type, string $output) use (&$allLogs) {
$allLogs .= removeAnsiColors($output);
});
if ($this->showTimeStamps) {
$allLogs = str($allLogs)->split('/\n/')->sort(function ($a, $b) {
$a = explode(' ', $a);
$b = explode(' ', $b);
return $a[0] <=> $b[0];
})->join("\n");
}
return sanitizeLogsForExport($allLogs);
}
public function render()
{
return view('livewire.project.shared.get-logs');