Sources
A source listens to a part of Symfony and creates an entry.
Overview
Enable a source with sources.<name>: true. Then add #[Auditable] to the class or the controller method to record.
| Source | Package | Actions | Put #[Auditable] on |
|---|---|---|---|
http_kernel | - | ACCESS | The controller class or method |
console | symfony/console | EXECUTE | The command class |
doctrine_orm | doctrine/orm, doctrine/doctrine-bundle | INSERT, UPDATE, DELETE | The entity class |
doctrine_odm | doctrine/mongodb-odm-bundle | INSERT, UPDATE, DELETE | The document class |
security | symfony/security-bundle | LOGIN, LOGIN_FAILURE, LOGOUT, SWITCH_USER | Nothing: each event is recorded |
messenger | symfony/messenger | MESSAGE_SENT, MESSAGE_HANDLED, MESSAGE_FAILED | The message class |
workflow | symfony/workflow | WORKFLOW_COMPLETED | The subject class |
Enable a source
symfonycorp_audit_log:
sources:
http_kernel: true
console: true
messenger: trueuse SymfonyCorp\AuditLog\Attribute\Auditable;
#[Auditable]
class ImportCommand extends Command {} // each run is recorded
#[Auditable]
class SendInvoice {} // sending to a transport, handling and failure are recorded
class BookController
{
#[Auditable]
public function delete(): Response {} // only this action is recorded
}Each entry also gets the values of the enabled context providers, such as the user and the IP.
Console
Each run of an #[Auditable] command gives one EXECUTE entry when the command ends. The context has command, the command name, and exit_code.
Good to know - a console command has no logged-in user, so its entries have no author.
Messenger
The source records an #[Auditable] message when it is sent to a transport (MESSAGE_SENT), when a worker handles it (MESSAGE_HANDLED), and when its handling fails (MESSAGE_FAILED). The context has message_class. A MESSAGE_FAILED entry also has will_retry.
To keep only some of these entries, drop the others with a PreAuditLogEvent listener.
Workflow
Each completed transition on an #[Auditable] subject gives one WORKFLOW_COMPLETED entry. The context has workflow, transition and subject_class.
Your own source
Your code can also create entries. See Manual logging and Extend the bundle.