lasthourcloud/app/Http/Livewire/Project/Shared/GetLogs.php

48 lines
1.4 KiB
PHP
Raw Normal View History

2023-10-02 11:38:16 +00:00
<?php
namespace App\Http\Livewire\Project\Shared;
use App\Models\Server;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
class GetLogs extends Component
{
public string $outputs = '';
public string $errors = '';
public Server $server;
public ?string $container = null;
public ?bool $streamLogs = false;
2023-10-19 11:32:03 +00:00
public ?bool $showTimeStamps = true;
2023-10-02 12:01:54 +00:00
public int $numberOfLines = 100;
2023-10-02 11:38:16 +00:00
public function doSomethingWithThisChunkOfOutput($output)
{
$this->outputs .= $output;
}
public function instantSave()
{
}
public function getLogs($refresh = false)
{
if ($this->container) {
2023-10-19 11:32:03 +00:00
if ($this->showTimeStamps) {
$sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} -t {$this->container}");
} else {
$sshCommand = generateSshCommand($this->server, "docker logs -n {$this->numberOfLines} {$this->container}");
}
2023-10-02 11:38:16 +00:00
if ($refresh) {
$this->outputs = '';
}
$command = Process::run($sshCommand);
$output = $command->output();
$error = $command->errorOutput();
$this->doSomethingWithThisChunkOfOutput($output);
$this->doSomethingWithThisChunkOfOutput($error);
2023-10-02 11:38:16 +00:00
}
}
public function render()
{
return view('livewire.project.shared.get-logs');
}
}