PHP code example of salioudiabate / log-viewer

1. Go to this page and download the library: Download salioudiabate/log-viewer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

salioudiabate / log-viewer example snippets


use Salioudiabate\LogViewer\Livewire\LogTable;

Route::get('/logs', LogTable::class)
    ->middleware(['web', 'auth']) // and/or `can:...` — see Authorization below
    ->name('logs.index');

// config/log-viewer.php
'sources' => [
    'laravel' => [
        'label' => 'Laravel',
        'dir' => storage_path('logs'),
        'pattern' => 'laravel*.log',
        'format' => 'laravel',
    ],
    'horizon' => [
        'label' => 'Horizon',
        'path' => '/var/log/myapp/horizon.log', // a single file instead of a dir+pattern
        'format' => 'laravel',
    ],
    'api-service' => [
        'label' => 'API Service',
        'path' => '/var/log/myapp/api.log',
        'format' => 'json', // ndjson — Go's zap/zerolog, Node's pino, Python's structlog, ...
    ],
],

// config/log-viewer.php
'redact' => [
    '/Bearer\s+[A-Za-z0-9\-_.]+/i' => 'Bearer [REDACTED]',
    '/"password"\s*:\s*"[^"]*"/i' => '"password":"[REDACTED]"',
    '/(api[_-]?key|secret|token)=([^&\s]+)/i' => '$1=[REDACTED]',
],

// config/log-viewer.php
'authorize' => 'log-viewer.view',
'authorize_clear' => 'log-viewer.clear', // deliberately separate — see below

// AppServiceProvider::boot()
Gate::define('log-viewer.view', fn (User $user) => $user->hasPermission('view logs'));
Gate::define('log-viewer.clear', fn (User $user) => $user->hasPermission('purge logs'));

// config/log-viewer.php
'middleware' => ['web', 'auth'],
'download_url_ttl' => 60, // seconds a generated link stays valid

// routes/console.php or a scheduler service provider
$schedule->command('log-viewer:prune-backups')->daily();

// config/log-viewer.php
'color_scheme' => 'light', // null (follow the OS), 'light' or 'dark'
'modal_max_width' => '4xl', // entry-detail modal: a modal width token or any CSS length

use Livewire\Livewire;
use Salioudiabate\LogViewer\Livewire\LogTable;

Livewire::test(LogTable::class)
    ->assertSee('error')
    ->set('search', 'timeout')
    ->assertSee('Connection timeout');
bash
php artisan vendor:publish --tag=log-viewer-config
bash
php artisan vendor:publish --tag=log-viewer-translations
bash
php artisan vendor:publish --tag=log-viewer-views