Skip to content
This repository was archived by the owner on Mar 29, 2026. It is now read-only.

Commit 80e50fc

Browse files
committed
feat: expand audit logging and refresh README
Add retention pruning, broader auth event logging, ignored-field controls, and richer activity diffs. Refresh the README to document the new behavior.
1 parent c63819f commit 80e50fc

21 files changed

Lines changed: 1284 additions & 92 deletions

README.md

Lines changed: 182 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,122 @@
1-
Maintained fork for Z3d0X
1+
Maintained fork of the original package by Z3d0X.
22

3-
`composer require mradder/filament-logger`
4-
5-
# Activity logger for filament
3+
# Filament Logger
64

75
[![Latest Version on Packagist](https://img.shields.io/packagist/v/mradder/filament-logger.svg?style=for-the-badge)](https://packagist.org/packages/mradder/filament-logger)
86
[![Total Downloads](https://img.shields.io/packagist/dt/mradder/filament-logger.svg?style=for-the-badge)](https://packagist.org/packages/mradder/filament-logger)
97

10-
<p align="center" class="filament-hidden">
11-
<img alt="logger banner" src="https://raw.githubusercontent.com/mradder/filament-logger/main/art/banner.jpeg" />
12-
</p>
8+
Audit activity inside Filament using [spatie/laravel-activitylog](https://spatie.be/docs/laravel-activitylog).
139

14-
Configurable activity logger for filament.
15-
Powered by `spatie/laravel-activitylog`
10+
This package gives you a ready-made Filament activity log resource plus automatic logging for resource changes, selected models, auth activity, and notifications.
1611

17-
## Features
18-
You can choose what you want to log and how to log it.
19-
- Log Filament Resource Events
20-
- Log Login Event
21-
- Log Notification Events
22-
- Log Model Events
23-
- Easily extendable to log custom events
12+
## Highlights
2413

25-
Note: By default this package will log Filament Resource Events, Access(Login) Events, and Notification Events. If you want to log a model that is not a FilamentResource you will have to manually register in the config file.
14+
- Filament activity log resource with searchable filters and a structured diff view
15+
- Resource and model lifecycle logging, including create, update, delete, restore, force-delete, and replicate flows
16+
- Auth event logging for login, logout, failed login, lockout, password reset, and 2FA recovery usage
17+
- Notification logging
18+
- Sensitive data redaction, anonymized IP logging, and stricter authorization defaults
19+
- Configurable ignored fields per model and per resource
20+
- Built-in pruning command for retention by age and log name
2621

27-
## Installation
22+
## Requirements
2823

29-
| Plugin Version | Filament Version |
30-
|----------------|------------------|
31-
| < 0.5.x | ^2.11 |
32-
| >= 0.6.0 | 3.x |
24+
| Package | Version |
25+
|---|---|
26+
| PHP | `^8.4` |
27+
| Filament | `^3.0` |
28+
| Laravel contracts | `^11.0` or `^12.0` |
3329

34-
This package uses [spatie/laravel-activitylog](https://spatie.be/docs/laravel-activitylog), instructions for its setup can be found [here](https://spatie.be/docs/laravel-activitylog/v4/installation-and-setup)
30+
## Installation
3531

36-
You can install the package via composer:
32+
Install the package:
3733

3834
```bash
3935
composer require mradder/filament-logger
4036
```
41-
After that run the install command:
37+
38+
Publish the package config and the Spatie activity log migrations:
4239

4340
```bash
4441
php artisan filament-logger:install
4542
```
46-
This will publish the config & migrations from `spatie/laravel-activitylog`
4743

48-
For Filament v3, you need to register a resource in PanelProvider
44+
Run your migrations:
45+
46+
```bash
47+
php artisan migrate
48+
```
49+
50+
Register the activity log resource in your panel provider:
51+
4952
```php
53+
use Filament\Panel;
54+
5055
public function panel(Panel $panel): Panel
5156
{
5257
return $panel
5358
->resources([
54-
config('filament-logger.activity_resource')
59+
config('filament-logger.activity_resource'),
5560
]);
5661
}
5762
```
63+
5864
## Authorization
59-
`ActivityResource` now uses strict authorization by default. If there is no registered policy, or the policy does not implement `viewAny` / `view`, the log resource is denied instead of falling back to Filament's permissive default.
6065

61-
After generating a policy, register `Spatie\Activitylog\Models\Activity` to use that policy in the AuthServiceProvider.
66+
The activity log resource is intentionally strict by default.
67+
68+
If no policy is registered for the activity model, or the policy does not implement `viewAny` and `view`, the resource is denied instead of falling back to Filament's permissive default behavior.
69+
70+
After generating a policy, register it in your auth service provider:
71+
6272
```php
6373
<?php
64-
74+
6575
namespace App\Providers;
66-
76+
6777
use App\Policies\ActivityPolicy;
6878
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
6979
use Spatie\Activitylog\Models\Activity;
70-
80+
7181
class AuthServiceProvider extends ServiceProvider
7282
{
7383
protected $policies = [
74-
// Update `Activity::class` with the one defined in `config/activitylog.php`
7584
Activity::class => ActivityPolicy::class,
7685
];
77-
//...
7886
}
7987
```
80-
> If you are using [Shield](https://filamentphp.com/plugins/shield) just register the ActivityPolicy generated by it
8188

82-
If you need the previous behavior for a legacy install, you can disable strict policy enforcement:
89+
If you use a custom activity model in `config/activitylog.php`, map that model instead.
90+
91+
If you need the old behavior for a legacy install:
8392

8493
```php
8594
'authorization' => [
8695
'strict' => false,
8796
],
8897
```
8998

90-
## Security defaults
91-
This package now applies a few safer defaults out of the box:
99+
## What Gets Logged
100+
101+
Out of the box the package logs:
92102

93-
- `ActivityResource` requires explicit policy methods when `authorization.strict` is enabled.
94-
- Sensitive keys such as passwords, tokens, secrets, and recovery codes are redacted before being stored in activity properties.
95-
- Access logs anonymize IP addresses and trim user agents by default.
96-
- Notification recipients are not logged unless `notifications.log_recipient` is explicitly enabled.
103+
- Filament resource model events
104+
- auth/access activity
105+
- notification events
97106

98-
Example overrides:
107+
If you want to log additional non-resource models, register them in `filament-logger.models.register`.
108+
109+
## Default Privacy and Security Behavior
110+
111+
The package ships with a few safer defaults:
112+
113+
- sensitive keys such as passwords, tokens, secrets, and recovery codes are redacted before storage
114+
- access logs anonymize IP addresses
115+
- user agents are trimmed
116+
- notification recipients are not logged unless explicitly enabled
117+
- the activity resource requires explicit policies when strict authorization is enabled
118+
119+
Example privacy-related overrides:
99120

100121
```php
101122
'redacted_placeholder' => '[REDACTED]',
@@ -113,40 +134,144 @@ Example overrides:
113134
],
114135
```
115136

116-
## Translations
117-
Publish the translations using:
137+
## Configuration Guide
138+
139+
### Resource Logging
140+
141+
Resource observers are enabled by default and can ignore noisy attributes globally, per model, or per Filament resource:
142+
143+
```php
144+
'resources' => [
145+
'enabled' => true,
146+
'ignore' => ['updated_at', 'remember_token'],
147+
'ignore_for_models' => [
148+
App\Models\User::class => ['last_seen_at', 'login_count'],
149+
],
150+
'ignore_for_resources' => [
151+
App\Filament\Resources\UserResource::class => ['last_seen_at', 'login_count'],
152+
],
153+
],
154+
```
155+
156+
### Model Logging
157+
158+
Register additional Eloquent models that are not managed through Filament resources:
159+
160+
```php
161+
'models' => [
162+
'enabled' => true,
163+
'register' => [
164+
App\Models\User::class,
165+
],
166+
'ignore' => ['updated_at', 'remember_token'],
167+
'ignore_for' => [
168+
App\Models\User::class => ['last_seen_at', 'login_count'],
169+
],
170+
],
171+
```
172+
173+
### Access Logging
174+
175+
Auth event logging is configurable per event:
176+
177+
```php
178+
'access' => [
179+
'events' => [
180+
'login' => true,
181+
'logout' => true,
182+
'failed' => true,
183+
'lockout' => true,
184+
'password_reset' => true,
185+
'two_factor_recovery' => true,
186+
],
187+
],
188+
```
189+
190+
The 2FA recovery event is only registered when the Fortify event class is available.
191+
192+
### Diff Formatting
193+
194+
The activity detail page renders old/new values using a structured diff view. You can adjust how large values are displayed:
195+
196+
```php
197+
'diff' => [
198+
'collapse_after' => 120,
199+
'pretty_print_json' => true,
200+
],
201+
```
202+
203+
## Retention and Pruning
204+
205+
Prune old activity records with:
118206

119207
```bash
120-
php artisan vendor:publish --tag="filament-logger-translations"
208+
php artisan filament-logger:prune
209+
```
210+
211+
Examples:
212+
213+
```bash
214+
php artisan filament-logger:prune --days=90
215+
php artisan filament-logger:prune --days=90 --log-name=Access --log-name=Resource
216+
php artisan filament-logger:prune --days=90 --except-log-name=Notification
217+
php artisan filament-logger:prune --dry-run
121218
```
122219

123-
## Activity Model resolution
124-
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`.
220+
You can also set defaults in config:
221+
222+
```php
223+
'pruning' => [
224+
'days' => 365,
225+
'only' => [],
226+
'except' => [],
227+
],
228+
```
229+
230+
Recommended scheduler entry:
231+
232+
```php
233+
use Illuminate\Support\Facades\Schedule;
234+
235+
Schedule::command('filament-logger:prune')->daily();
236+
```
125237

126238
## Screenshots
239+
127240
<img alt="logger-index" src="https://raw.githubusercontent.com/mradder/filament-logger/main/art/list-screenshot.png">
128241
<img alt="logger-detail-1" src="https://raw.githubusercontent.com/mradder/filament-logger/main/art/view-screenshot-1.png">
129242
<img alt="logger-detail-2" src="https://raw.githubusercontent.com/mradder/filament-logger/main/art/view-screenshot-2.png">
130243

244+
## Translations
245+
246+
Publish translations with:
247+
248+
```bash
249+
php artisan vendor:publish --tag="filament-logger-translations"
250+
```
251+
252+
## Activity Model Resolution
253+
254+
The Filament resource resolves the activity model from `activitylog.activity_model` in `config/activitylog.php`.
255+
131256
## Changelog
132257

133-
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
258+
See [CHANGELOG](CHANGELOG.md) for recent changes.
134259

135260
## Contributing
136261

137-
Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.
262+
See [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for contribution guidelines.
138263

139-
## Security Vulnerabilities
264+
## Security
140265

141-
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
266+
Please review [our security policy](../../security/policy) for responsible disclosure details.
142267

143268
## Credits
144269

145-
- [Ziyaan Hassan](https://github.com/Z3d0X) - Original Developer
146-
- [Daniel 'MrAdder' Green](https://github.com/MrAdder)
147-
- [Spatie Activitylog Contributors](https://github.com/spatie/laravel-activitylog#credits)
270+
- [Ziyaan Hassan](https://github.com/Z3d0X) - original developer
271+
- [Daniel Green](https://github.com/MrAdder)
272+
- [Spatie Activitylog Contributors](https://github.com/spatie/laravel-activitylog#credits)
148273
- [All Contributors](../../contributors)
149274

150275
## License
151276

152-
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
277+
The MIT License (MIT). See [LICENSE.md](LICENSE.md) for details.

art/banner.jpeg

-282 KB
Binary file not shown.

config/filament-logger.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
'recovery_codes',
2727
],
2828

29+
'diff' => [
30+
'collapse_after' => 120,
31+
'pretty_print_json' => true,
32+
],
33+
34+
'pruning' => [
35+
'days' => 365,
36+
'only' => [],
37+
'except' => [],
38+
],
39+
2940
'activity_resource' => \MrAdder\FilamentLogger\Resources\ActivityResource::class,
3041
'scoped_to_tenant' => true,
3142
'navigation_sort' => null,
@@ -39,6 +50,16 @@
3950
'exclude' => [
4051
//App\Filament\Resources\UserResource::class,
4152
],
53+
'ignore' => [
54+
'updated_at',
55+
'remember_token',
56+
],
57+
'ignore_for_models' => [
58+
//App\Models\User::class => ['last_seen_at', 'login_count'],
59+
],
60+
'ignore_for_resources' => [
61+
//App\Filament\Resources\UserResource::class => ['last_seen_at', 'login_count'],
62+
],
4263
'cluster' => null,
4364
'navigation_group' =>'Settings',
4465
],
@@ -52,6 +73,19 @@
5273
'anonymize_ip' => true,
5374
'store_user_agent' => true,
5475
'user_agent_max_length' => 255,
76+
'identifier_keys' => [
77+
'email',
78+
'username',
79+
'login',
80+
],
81+
'events' => [
82+
'login' => true,
83+
'logout' => true,
84+
'failed' => true,
85+
'lockout' => true,
86+
'password_reset' => true,
87+
'two_factor_recovery' => true,
88+
],
5589
],
5690

5791
'notifications' => [
@@ -68,6 +102,13 @@
68102
'log_name' => 'Model',
69103
'color' => 'warning',
70104
'logger' => \MrAdder\FilamentLogger\Loggers\ModelLogger::class,
105+
'ignore' => [
106+
'updated_at',
107+
'remember_token',
108+
],
109+
'ignore_for' => [
110+
//App\Models\User::class => ['last_seen_at', 'login_count'],
111+
],
71112
'register' => [
72113
//App\Models\User::class,
73114
],

0 commit comments

Comments
 (0)