Docs / Sources / Overview

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.

SourcePackageActionsPut #[Auditable] on
http_kernel-ACCESSThe controller class or method
consolesymfony/consoleEXECUTEThe command class
doctrine_ormdoctrine/orm, doctrine/doctrine-bundleINSERT, UPDATE, DELETEThe entity class
doctrine_odmdoctrine/mongodb-odm-bundleINSERT, UPDATE, DELETEThe document class
securitysymfony/security-bundleLOGIN, LOGIN_FAILURE, LOGOUT, SWITCH_USERNothing: each event is recorded
messengersymfony/messengerMESSAGE_SENT, MESSAGE_HANDLED, MESSAGE_FAILEDThe message class
workflowsymfony/workflowWORKFLOW_COMPLETEDThe subject class

Enable a source

config/packages/symfonycorp_audit_log.yaml
symfonycorp_audit_log:
    sources:
        http_kernel: true
        console: true
        messenger: true
src/
use 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.