| Install | |
|---|---|
composer require riodwanto/filament-logger |
|
| Latest Version: | v3.0.0 |
| PHP: | ^8.1|^8.2 |
A comprehensive activity logging solution for Filament applications, powered by spatie/laravel-activitylog. Track user actions, model changes, and system events with a beautiful, configurable interface.
By default, this package logs:
Note: If you want to log models that are not Filament Resources, you'll need to manually register them in the configuration file.
This package uses spatie/laravel-activitylog, instructions for its setup can be found here
composer require riodwanto/filament-logger
php artisan filament-logger:install
This command will:
spatie/laravel-activitylogphp artisan migrate
<?php
namespace App\Providers;
use Filament\Panel;
use Filament\PanelProvider;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->resources([
config('filament-logger.activity_resource')
]);
}
}
After installation, you'll immediately see activity logs for:
Navigate to your Filament admin panel and look for the "Activity Log" menu item to view the logs.
The package is highly configurable through the config/filament-logger.php file. Here are the main configuration options:
return [
'datetime_format' => 'd/m/Y H:i:s',
'date_format' => 'd/m/Y',
'activity_resource' => \Riodwanto\FilamentLogger\Resources\ActivityResource::class,
'scoped_to_tenant' => true,
'navigation_sort' => null,
];
'resources' => [
'enabled' => true,
'log_name' => 'Resource',
'logger' => \Riodwanto\FilamentLogger\Loggers\ResourceLogger::class,
'color' => 'success',
'exclude' => [
// App\Filament\Resources\UserResource::class,
],
'cluster' => null,
'navigation_group' => 'Settings',
],
'access' => [
'enabled' => true,
'logger' => \Riodwanto\FilamentLogger\Loggers\AccessLogger::class,
'color' => 'danger',
'log_name' => 'Access',
],
'notifications' => [
'enabled' => true,
'logger' => \Riodwanto\FilamentLogger\Loggers\NotificationLogger::class,
'color' => null,
'log_name' => 'Notification',
],
'models' => [
'enabled' => true,
'log_name' => 'Model',
'color' => 'warning',
'logger' => \Riodwanto\FilamentLogger\Loggers\ModelLogger::class,
'register' => [
// App\Models\User::class,
// App\Models\Post::class,
],
],
You can create custom loggers for specific events:
'custom' => [
[
'log_name' => 'Payment',
'color' => 'primary',
'logger' => \App\Loggers\PaymentLogger::class,
],
],
Create a custom logger by extending the AbstractModelLogger:
<?php
namespace App\Loggers;
use Riodwanto\FilamentLogger\Loggers\AbstractModelLogger;
class PaymentLogger extends AbstractModelLogger
{
protected function getLogName(): string
{
return 'Payment';
}
public function paymentProcessed($payment)
{
$this->log($payment, 'Processed', 'Payment was processed successfully');
}
}
To exclude specific resources from being logged:
'resources' => [
'exclude' => [
\App\Filament\Resources\UserResource::class,
\App\Filament\Resources\ActivityResource::class,
],
],
// In your config
'navigation_group' => 'Audit',
'navigation_sort' => 10,
'scoped_to_tenant' => false, // Set to false for global logs
'datetime_format' => 'Y-m-d H:i:s', // Database format
'date_format' => 'Y-m-d', // Display format
The package supports Filament's multi-tenancy out of the box. Set scoped_to_tenant to true in your config to enable tenant-scoped activity logs.
The activity log interface includes powerful filtering options:
You can easily add export functionality by extending the ActivityResource:
use Filament\Tables\Actions\BulkAction;
// In your ActivityResource table method
BulkAction::make('export')
->label('Export Selected')
->icon('heroicon-o-download')
->action(function ($records) {
// Your export logic here
}),
If you see missing translation keys, publish the translations:
php artisan vendor:publish --tag="filament-logger-translations"
For high-traffic applications:
If logs aren't scoped correctly:
scoped_to_tenant settingEnable debug mode to see detailed logging information:
// In your config/filament-logger.php
'debug' => env('FILAMENT_LOGGER_DEBUG', false),
To enforce policies on ActivityResource, after generating a policy, you would need to register Spatie\Activitylog\Models\Activity to use that policy in the AuthServiceProvider.
<?php
namespace App\Providers;
use App\Policies\ActivityPolicy;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Spatie\Activitylog\Models\Activity;
class AuthServiceProvider extends ServiceProvider
{
protected $policies = [
// Update `Activity::class` with the one defined in `config/activitylog.php`
Activity::class => ActivityPolicy::class,
];
//...
}
If you are using Shield just register the ActivityPolicy generated by it
Publish the translations using:
php artisan vendor:publish --tag="filament-logger-translations"
The main Activity class being used by the Filament Resource instance will be resolved by Spatie's service provider, which loads the model defined by the configuration key found at activitylog.activity_model in config/activitylog.php.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
If you encounter any issues or have questions:
We welcome contributions! Please see our Contributing Guide for details on how to:
Please see CHANGELOG for more information on what has changed recently.
If you're upgrading from the original package:
Update Composer dependency:
composer remove z3d0x/filament-logger
composer require riodwanto/filament-logger
Update namespace references (if any):
Z3d0X\FilamentLogger to Riodwanto\FilamentLoggerClear caches:
php artisan config:clear
php artisan cache:clear
Test your application to ensure everything works correctly
The API remains largely the same, so most applications should work without changes.