Logging Bundle

0.5.1 2020-12-16 16:35 UTC

This package is not auto-updated.

Last update: 2021-05-05 18:17:00 UTC


This bundle will add a Monolog processor that adds the client IP, user-agent, kernel environment, user and application name to the extra data of each log line. It also provides an event listener that listens to all events, logging any that implement the LoggableEvent interface.


composer require vivait/logging-bundle

Include the bundle in your AppKernel:

// app/AppKernel.php
class AppKernel extends Kernel
    public function registerBundles()
        $bundles = array(
            // ...
            new Vivait\LoggingBundle\VivaitLoggingBundle(),

        // ...

Add the following configuration to your config.yml:

    application_name: MyAppName
    # Alternatively...
    application_name: '%my_name_parameter%'


To use the loggable event listener, simply fire any event that implements the LoggableEvent interface, such as the GenericLogEvent that is part of this bundle. To use the extra data, set up a Monolog formatter with the appropriate arguments, or use the provided vivait.logging_bundle.log_formatter service, e.g.

# config.yml
            type: stream
            path: '%kernel.logs_dir%/%kernel.environment%.log'
            level: debug
            formatter: vivait.logging_bundle.log_formatter

which will display logs in the following format:

[%%datetime%%] [%%extra.App%%] [%%extra.Environment%%] [%%extra.User%%] %%channel%%.%%level_name%%: %%message%% [%%extra.IP%%] [%%extra.UA%%] %%context%% %%extra%%