diff --git a/app/Livewire/Project/Shared/GetLogs.php b/app/Livewire/Project/Shared/GetLogs.php index 8fda35a4a..5f8046efd 100644 --- a/app/Livewire/Project/Shared/GetLogs.php +++ b/app/Livewire/Project/Shared/GetLogs.php @@ -21,6 +21,8 @@ class GetLogs extends Component { + public const MAX_LOG_LINES = 50000; + public string $outputs = ''; public string $errors = ''; @@ -123,6 +125,9 @@ public function getLogs($refresh = false) if ($this->numberOfLines <= 0 || is_null($this->numberOfLines)) { $this->numberOfLines = 1000; } + if ($this->numberOfLines > self::MAX_LOG_LINES) { + $this->numberOfLines = self::MAX_LOG_LINES; + } if ($this->container) { if ($this->showTimeStamps) { if ($this->server->isSwarm()) { @@ -183,6 +188,50 @@ public function copyLogs(): string 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'); diff --git a/resources/views/livewire/project/shared/get-logs.blade.php b/resources/views/livewire/project/shared/get-logs.blade.php index 03c049874..2d964f0bb 100644 --- a/resources/views/livewire/project/shared/get-logs.blade.php +++ b/resources/views/livewire/project/shared/get-logs.blade.php @@ -251,8 +251,8 @@ class="flex items-center justify-between gap-2 px-4 py-2 border-b dark:border-co
Lines: -
- +
+ +
+
+ + +
+
+