Async writes
Send the entries through Messenger and write them on a worker, not during the request.
Enable the message bus
The message_bus option sends the entries through a Messenger bus. It needs symfony/messenger:
$ composer require symfony/messengersymfonycorp_audit_log:
message_bus: ~ # uses messenger.default_bus
# message_bus: { service: messenger.bus.audit }service: the service id of the bus. Default:messenger.default_bus.
Route the entries
Route AuditEntry to an async transport to write the entries on a worker. Without the routing, the bus writes them at once:
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
routing:
'SymfonyCorp\AuditLog\Entry\AuditEntry': asyncRun a worker:
$ bin/console messenger:consume asyncFailed messages
Configure a failure_transport. Without it, Messenger drops an entry after the last retry.
Personal data - the transport holds the full entries, with their personal data. Protect it as you protect the audit storage. See Personal data.