Anvil
Anvil - The mobile companion for Laravel Forge. Available now. Download for iOS

Purging and Exporting Logs

Purging Old Logs

You may clear the old authentication log records using the authentication-log:purge Artisan command:

1php artisan authentication-log:purge

Records that are older than the number of days specified in the purge option in your config/authentication-log.php will be deleted.

1'purge' => 365,

You can also schedule the command at an interval:

1$schedule->command('authentication-log:purge')->monthly();

Exporting Logs

Export authentication logs to CSV or JSON format using the authentication-log:export command:

Basic Export

1# Export all logs to CSV
2php artisan authentication-log:export --format=csv
3 
4# Export all logs to JSON
5php artisan authentication-log:export --format=json

Filtered Export

1# Export logs from last 30 days
2php artisan authentication-log:export --format=csv --days=30
3 
4# Export logs for specific user
5php artisan authentication-log:export --format=json --user=1
6 
7# Specify output file
8php artisan authentication-log:export --format=csv --output=logs.csv
9 
10# Combine filters
11php artisan authentication-log:export --format=csv --days=7 --user=1 --output=user-logs.csv

Export Options

  • --format: Export format (csv or json) - default: csv
  • --days: Export logs from last N days
  • --user: Filter by user ID
  • --output: Output file path (default: authentication-logs-{format}-{timestamp}.{ext})

Export Contents

The export includes:

  • Log ID
  • User information (type, ID, email)
  • IP address and user agent
  • Device information (ID, name, trusted status)
  • Login/logout timestamps
  • Success status
  • Suspicious activity flags
  • Location data (if available)