gboquizosanchez/filament-log-viewer
Installation
composer require gboquizosanchez/filament-log-viewer
Publish the config file:
php artisan vendor:publish --provider="Gboquizosanchez\FilamentLogViewer\FilamentLogViewerServiceProvider" --tag="filament-log-viewer-config"
Register the Plugin
Add to your PanelProvider (e.g., App\Providers/Filament/AdminPanelProvider):
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Gboquizosanchez\FilamentLogViewer\FilamentLogViewerPlugin::make(),
]);
}
First Use Case
Access the log viewer via the Filament sidebar (default location: Logs under the main menu). Immediately inspect recent log entries, filter by severity (e.g., error, warning), and search for specific keywords.
Log Filtering & Search
debug, info, error) via dropdown or checkboxes.enable_regex_search = true).Log Inspection
Log Management
log_max_files)..txt or .json (customize via download_format in config).Integration with Filament Features
error) appear (extend via LogViewerService events).FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
$plugin->canViewLogs(fn (User $user) => $user->isAdmin());
});
Custom Log Sources
single or stack channels):
FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
$plugin->logChannels(['single', 'stack', 'custom_channel']);
});
Log Highlighting Customize syntax highlighting for log entries via config:
'highlighting' => [
'error' => '#ff6b6b', // Custom color for errors
'stack_trace' => true, // Enable stack trace syntax highlighting
],
Log Retention
Automatically purge old logs using Laravel’s Log::clean() or override via:
FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
$plugin->logMaxFiles(5); // Keep only 5 log files
});
Event Listeners Hook into log events to add metadata or modify entries:
public function boot()
{
\Gboquizosanchez\FilamentLogViewer\Events\LogEntryCreated::listen(function ($entry) {
$entry->context['custom_key'] = 'value';
});
}
Localization Translate UI strings (e.g., "Clear Selected") via Filament’s localization system:
FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
$plugin->translationPrefix('filament-log-viewer');
});
Performance with Large Logs
log_max_files to cap stored files:
'log_max_files' => 3, // Keep only 3 log files (~1 week for daily logs)
Stack Trace Parsing
LogEntry model or override the formatStackTrace() method in the service provider.Permission Conflicts
configureUsing() after plugin registration.Config Overrides
php artisan config:clear
Dark Mode Glitches
styles directory or adjust highlighting colors.Log Entry Not Showing?
logChannels config.storage/logs/ and is readable by the web server.Stack Trace Truncated
stack_trace_max_lines in config (default: 50).Search Not Working
enable_regex_search is false if using simple keyword searches (regex can be resource-intensive).Plugin Not Loading
config/filament.php under panel_providers.Custom Log Formatter Override the default log entry formatting by binding a custom formatter:
$this->app->bind(
\Gboquizosanchez\FilamentLogViewer\Contracts\LogEntryFormatter::class,
\App\Services\CustomLogFormatter::class
);
Add Log Actions Extend the log entry actions (e.g., "Replay Exception"):
FilamentLogViewer::configureUsing(function (FilamentLogViewer $plugin) {
$plugin->registerAction(
\Gboquizosanchez\FilamentLogViewer\Actions\ReplayException::make()
);
});
Log Entry Metadata Inject additional data into log entries via middleware or service provider:
\Gboquizosanchez\FilamentLogViewer\Events\LogEntryCreated::listen(function ($entry) {
$entry->context['user_id'] = auth()->id();
});
Custom Log Storage
Use a database-backed log system (e.g., spatie/laravel-log) by extending the LogViewerService:
public function getLogs(): array
{
return \App\Models\StoredLog::query()->get()->toArray();
}
How can I help you explore Laravel packages today?