Manual logging
Inject AuditLogger to record your own entries.
Record an entry
use SymfonyCorp\AuditLog\AuditLogger;
use SymfonyCorp\AuditLog\Entry\AuditEntry;
$this->auditLogger->log(new AuditEntry(
source: 'order',
action: 'CANCEL',
message: 'Order #{order_id} cancelled',
context: ['order_id' => $order->getId()],
));AuditEntry takes these arguments:
source,actionandmessage: required strings.occurredAt: a\DateTimeImmutable. Default: now.context: an array of key-value data. Default:[].id: a UUID string. Default: a new UUIDv7.
AuditLogger adds the values of the context providers and calls your PreAuditLogEvent listeners, as for the entries of a source. See Extend the bundle.
Message placeholders
The message is a template with {placeholders}. Put the values in context, not in the message. Then you can group entries by message, and translate the message later.
The bundle replaces the placeholders at display time. In Twig, use the audit_log_message filter:
{{ entry|audit_log_message }}In PHP, inject SymfonyCorp\AuditLog\Message\MessageRenderer and call render($entry):
$message = $this->messageRenderer->render($entry); // Order #42 cancelledYour own source
To record the entries of a part of your application in one place, write a source. See Extend the bundle.