Docs / Privacy & Compliance / Retention

Retention

The bundle keeps entries until you delete them. Choose a retention period for each purpose, then run audit-log:purge on a schedule.

Choose a period

terminal
$ bin/console audit-log:purge --older-than="1 year" --force

Without --force, the command only shows how many entries it would delete.

Run the purge with Scheduler

With Symfony Scheduler:

src/Scheduler/AuditLogSchedule.php
use Symfony\Component\Console\Messenger\RunCommandMessage;
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;

#[AsSchedule('audit_log')]
final class AuditLogSchedule implements ScheduleProviderInterface
{
    public function getSchedule(): Schedule
    {
        return (new Schedule())->add(
            RecurringMessage::every('1 day', new RunCommandMessage('audit-log:purge --older-than="1 year" --force')),
        );
    }
}

Run the worker:

terminal
$ bin/console messenger:consume scheduler_audit_log

Run the purge with cron

crontab
0 3 * * * php /path/to/bin/console audit-log:purge --older-than="1 year" --force

Several outputs

The command purges one output per run. If more than one output supports purge, add one run per output with --output=<name>. For filesystem and stdout, use log rotation or the retention of your log platform.