diff --git a/app/Livewire/Project/Shared/GetLogs.php b/app/Livewire/Project/Shared/GetLogs.php index edcaf0f349..7bb73562cd 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 { @@ -40,6 +41,8 @@ class GetLogs extends Component public int $numberOfLines = 100; + public ?bool $wrapLines = false; + public function mount() { if (! is_null($this->resource)) { @@ -87,6 +90,36 @@ public function instantSave() } } } + $this->wrapLines = $this->wrapLines; + } + + 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) @@ -151,6 +184,7 @@ public function getLogs($refresh = false) } } + public function render() { return view('livewire.project.shared.get-logs'); diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php index b8e10890d4..640a66bb3a 100644 --- a/resources/views/livewire/project/shared/get-logs.blade.php +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -1,4 +1,4 @@ -