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
- For security logs, the CNIL recommends between six months and one year.
- The
doctrine_ormanddoctrine_odmchangesets copy your business data. Give them the retention period of this data. audit-log:purgedeletes by age only, for all the entries of one output. To keep two periods, use two outputs.
$ bin/console audit-log:purge --older-than="1 year" --forceWithout --force, the command only shows how many entries it would delete.
Run the purge with Scheduler
With Symfony Scheduler:
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:
$ bin/console messenger:consume scheduler_audit_logRun the purge with cron
0 3 * * * php /path/to/bin/console audit-log:purge --older-than="1 year" --forceSeveral 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.