diff --git a/app/Livewire/Project/Shared/GetLogs.php b/app/Livewire/Project/Shared/GetLogs.php index edcaf0f349..3f75d0040c 100644 --- a/app/Livewire/Project/Shared/GetLogs.php +++ b/app/Livewire/Project/Shared/GetLogs.php @@ -17,6 +17,7 @@ use App\Models\StandaloneRedis; use Illuminate\Support\Facades\Process; use Livewire\Component; +use Symfony\Component\Process\Exception\ProcessFailedException; class GetLogs extends Component { @@ -89,6 +90,35 @@ public function instantSave() } } + public function downloadLogs() + { + if (! $this->server->isFunctional() || ! $this->container) { + return null; + } + + $command = $this->server->isSwarm() + ? "docker service logs -t {$this->container}" + : "docker logs -t {$this->container}"; + + if ($this->server->isNonRoot()) { + $command = parseCommandsByLineForSudo(collect($command), $this->server); + $command = $command[0]; + } + + $sshCommand = generateSshCommand($this->server, $command); + + $logContent = ''; + + Process::run($sshCommand, function (string $type, string $output) use (&$logContent) { + $logContent .= $output; + }); + + return response()->streamDownload(function () use ($logContent) { + echo $logContent; + }, 'logs.txt'); + + } + public function getLogs($refresh = false) { if (! $this->server->isFunctional()) { diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php index b8e10890d4..881749f71a 100644 --- a/resources/views/livewire/project/shared/get-logs.blade.php +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -52,6 +52,7 @@ id="numberOfLines"> Refresh + Download Logs