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 @@ -
+
@@ -43,51 +49,74 @@
({{ $pull_request }})
@endif @if ($streamLogs) - + @endif
+ id="numberOfLines">
Refresh + Download Logs +
-
- + + stroke-width="2" d="M12 5v14m4-10l-4-4M8 9l4-4"/> + + + stroke-width="2" d="M12 5v14m4-4l-4 4m-4-4l4 4"/> + + + + @if ($outputs) -
{{ $outputs }}
+
+ @foreach (explode("\n", $outputs) as $line) +
+ + {{ $line }} +
+ @endforeach +
@else
Refresh to get the logs...
@endif @@ -95,3 +124,4 @@ class="fixed top-4 right-16" x-on:click="toggleScroll">
+