generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
86efae8
commit e507e48
Showing
6 changed files
with
202 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<x-pulse::card :cols="$cols" :rows="$rows" :class="$class"> | ||
<x-pulse::card-header | ||
name="Log Files" | ||
title="Log Files" | ||
details="Track Application Log Files" | ||
> | ||
<x-slot:icon> | ||
<x-pulse::icons.circle-stack /> | ||
</x-slot:icon> | ||
</x-pulse::card-header> | ||
|
||
<x-pulse::scroll :expand="$expand" wire:poll.5s=""> | ||
<div class="min-h-full flex flex-col"> | ||
@if ($servers->isNotEmpty()) | ||
@foreach ($servers as $server) | ||
<x-pulse::table> | ||
<x-pulse::thead> | ||
<tr> | ||
<x-pulse::th>Logfile</x-pulse::th> | ||
<x-pulse::th class="text-right">Size</x-pulse::th> | ||
</tr> | ||
</x-pulse::thead> | ||
<tbody> | ||
@foreach ($server->logFiles as $logFile) | ||
<tr class="h-2 first:h-0"></tr> | ||
<tr wire:key="log-file-{{ $logFile->name }}"> | ||
<x-pulse::td> | ||
<div class="flex items-center" title="{{ $logFile->name }}"> | ||
<div>{{ $logFile->name }}</div> | ||
</div> | ||
</x-pulse::td> | ||
<x-pulse::td numeric class="text-gray-700 dark:text-gray-300 font-bold"> | ||
{{ $logFile->readableSize }} | ||
</x-pulse::td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</x-pulse::table> | ||
@endforeach | ||
@else | ||
<x-pulse::no-results /> | ||
@endif | ||
</div> | ||
</x-pulse::scroll> | ||
</x-pulse::card> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Denniseilander\LogFiles\DataTransferObjects; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Number; | ||
|
||
class LogFile | ||
{ | ||
public function __construct( | ||
public string $name, | ||
public string $path, | ||
public int $size, | ||
public string $readableSize, | ||
) { | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'path' => $this->path, | ||
'size' => $this->size, | ||
'readable_size' => $this->readableSize, | ||
]; | ||
} | ||
|
||
public static function fromPath(string $path): self | ||
{ | ||
return new self( | ||
name: basename($path), | ||
path: $path, | ||
size: filesize($path), | ||
readableSize: Number::fileSize(filesize($path)), | ||
); | ||
} | ||
|
||
/** | ||
* @throws \JsonException | ||
*/ | ||
public static function multipleFromJson(string $json): Collection | ||
{ | ||
$data = json_decode( | ||
json: $json, | ||
associative: true, | ||
depth: 512, | ||
flags: JSON_THROW_ON_ERROR | ||
); | ||
|
||
return Collection::make($data)->map(function ($item) { | ||
return new self(...array_values($item)); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Denniseilander\LogFiles\Livewire; | ||
|
||
use Carbon\CarbonImmutable; | ||
use Denniseilander\LogFiles\DataTransferObjects\LogFile; | ||
use Illuminate\Contracts\View\View; | ||
use Illuminate\Support\Facades\View as ViewFacade; | ||
use Laravel\Pulse\Facades\Pulse; | ||
use Laravel\Pulse\Livewire\Card; | ||
use Livewire\Attributes\Lazy; | ||
|
||
#[Lazy] | ||
class LogFiles extends Card | ||
{ | ||
public function render(): View | ||
{ | ||
$servers = Pulse::values('log_files') | ||
->map(function (object $logFile) { | ||
$logFiles = LogFile::multipleFromJson($logFile->value); | ||
|
||
return (object) [ | ||
'serverName' => $logFile->key, | ||
'logFiles' => $logFiles, | ||
'updated_at' => CarbonImmutable::createFromTimestamp($logFile->timestamp), | ||
]; | ||
}); | ||
|
||
return ViewFacade::make('pulse-log-files::livewire.log-files', [ | ||
'servers' => $servers, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Denniseilander\LogFiles; | ||
|
||
use Denniseilander\LogFiles\Livewire\LogFiles; | ||
use Illuminate\Foundation\Application; | ||
use Livewire\LivewireManager; | ||
use Spatie\LaravelPackageTools\Package; | ||
use Spatie\LaravelPackageTools\PackageServiceProvider; | ||
|
||
class LogFilesServiceProvider extends PackageServiceProvider | ||
{ | ||
public function configurePackage(Package $package): void | ||
{ | ||
$package | ||
->name('pulse-log-files') | ||
->hasViews(); | ||
} | ||
|
||
public function packageBooted(): void | ||
{ | ||
$this->callAfterResolving('livewire', function (LivewireManager $livewire, Application $app) { | ||
$livewire->component('pulse.log-files', LogFiles::class); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Denniseilander\LogFiles\Services; | ||
|
||
use Denniseilander\LogFiles\DataTransferObjects\LogFile; | ||
use Illuminate\Support\Collection; | ||
|
||
class LogFilesService | ||
{ | ||
public function getFiles(): Collection | ||
{ | ||
return Collection::make(glob(storage_path('logs/*.log')) ?: []) | ||
->map(fn (string $logFile) => LogFile::fromPath($logFile)); | ||
} | ||
} |