PHP code example of achyutn / filament-log-viewer

1. Go to this page and download the library: Download achyutn/filament-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/ */

    

achyutn / filament-log-viewer example snippets


use AchyutN\FilamentLogViewer\FilamentLogViewer;

return $panel
    ->plugins([
        FilamentLogViewer::make(),
    ]);

return [
    // Set max file size to 20 MB
    'max_log_file_size' => env('LOG_MAX_SIZE_KB', 20480),

    // Disable deleting logs from the UI
    'enable_delete' => env('LOG_ENABLE_DELETE', false),

    // Truncate log contents on clear (false to delete the files entirely)
    'truncate_on_clear' => env('LOG_TRUNCATE_ON_CLEAR', true),

    // Disable copying logs as markdown
    'enable_copy_markdown' => env('LOG_ENABLE_COPY_MARKDOWN', true),

    // Show copy button for these log levels (comma-separated)
    'copy_markdown_levels' => explode(',', env('LOG_COPY_MARKDOWN_LEVELS', 'error')),

    // Skip caching parsed log rows between requests
    'disable_cache' => env('LOG_DISABLE_CACHE', false),
];

FilamentLogViewer::make()
    ->authorize(true);

// or

FilamentLogViewer::make()
    ->authorize(fn (): bool => auth()->user()->is_admin);

FilamentLogViewer::make()
    ->authorize(fn (): bool => auth()->check() && auth()->user()->can('View:LogTable'));

use AchyutN\FilamentLogViewer\FilamentLogViewer;

FilamentLogViewer::make()
    ->authorize(fn () => auth()->check())
    ->registerNavigation(true)
    ->navigationGroup('System')
    ->navigationIcon('heroicon-o-document-text')
    ->navigationLabel('Log Viewer')
    ->navigationSort(10)
    ->navigationUrl('/logs')
    ->pollingTime(null); // Set to null to disable polling

use AchyutN\FilamentLogViewer\Contracts\LogProvider;
use AchyutN\FilamentLogViewer\FilamentLogViewer;
use AchyutN\FilamentLogViewer\Providers\LocalLogProvider;

class CloudLogProvider extends LocalLogProvider implements LogProvider
{
    protected function getAllLogFiles(): array
    {
        return ['cloud.log', 'scheduler.log'];
    }
}

FilamentLogViewer::make()
    ->providerClass(CloudLogProvider::class)
    ->parserClass(MyParser::class)          // implements LogParser or extends FileLogParser
    ->errorSchemaClass(MyErrorSchema::class);

LOG_MAX_SIZE_KB=20480
LOG_ENABLE_DELETE=false
LOG_TRUNCATE_ON_CLEAR=true
LOG_ENABLE_COPY_MARKDOWN=false
LOG_COPY_MARKDOWN_LEVELS=error,warning
LOG_DISABLE_CACHE=false
bash
php artisan vendor:publish --tag=filament-log-viewer-config