Skip to content

Commit

Permalink
feat: added download logs button
Browse files Browse the repository at this point in the history
  • Loading branch information
yohannlog committed Jun 19, 2024
1 parent c3a4ae1 commit a39d5dc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/Livewire/Project/Shared/GetLogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/project/shared/get-logs.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
id="numberOfLines"></x-forms.input>
</div>
<x-forms.button type="submit">Refresh</x-forms.button>
<x-forms.button wire:click="downloadLogs">Download Logs</x-forms.button>
<x-forms.checkbox instantSave label="Stream Logs" id="streamLogs"></x-forms.checkbox>
<x-forms.checkbox instantSave label="Include Timestamps" id="showTimeStamps"></x-forms.checkbox>
</form>
Expand Down

0 comments on commit a39d5dc

Please sign in to comment.