Docs / Outputs / Overview

Outputs

An output stores the entries. Each enabled output receives each entry.

Overview

If one output fails, the other outputs still receive the entry. The bundle logs the failure at the error level, or throws it when silent_failures is false.

OutputPackageReadsPurgeSetup
dbaldoctrine/dbal, doctrine/doctrine-bundleYesYesYes
elasticsearchelasticsearch/elasticsearchYesYesYes
mongodbdoctrine/mongodb-odm-bundleYesYesYes
filesystem-NoNoYes
stdout-NoNoNo
in_memory-YesNoNo

Enable an output

Enable one or more outputs. Each output has its own page with its options:

config/packages/symfonycorp_audit_log.yaml
symfonycorp_audit_log:
    outputs:
        dbal: true
        stdout: true   # one JSON line per entry, for your log platform

If you have more than one readable output, select one with --output=<name> in the commands and ?output=<name> in the EasyAdmin URL. To write the entries on a worker, see Async writes.

Create the storage

The dbal, elasticsearch and mongodb outputs do not create their storage by default. Without it, a write can fail, and the bundle only logs the failure.

With Doctrine migrations, the dbal output adds its table to the Doctrine schema of its connection. Otherwise, run the setup command when you deploy. It does not change a storage that exists. It fails with a non-zero exit code on an error:

terminal
$ bin/console audit-log:setup
$ bin/console audit-log:setup --output=dbal

In development and in tests, you can let an output create its storage on the first write instead. If this fails, the bundle logs the failure, or throws it when silent_failures is false. Do not use it in production:

config/packages/dev/symfonycorp_audit_log.yaml
symfonycorp_audit_log:
    outputs:
        dbal:
            auto_setup: true

The auto_setup option exists for dbal, elasticsearch and mongodb. Its default value is false.

Show the failures in development

By default, a failing output, context provider or PreAuditLogEvent listener only logs the failure. In dev and test, set silent_failures: false to throw the failure instead:

config/packages/dev/symfonycorp_audit_log.yaml
symfonycorp_audit_log:
    silent_failures: false

Not in production - with the doctrine_orm and doctrine_odm sources, the bundle writes the entries after the commit. A failing output then makes flush() throw although the data is saved. Do not use silent_failures: false in production.