exbico/monolog-db-bundle

Symfony MonologDb Bundle

Installs: 1 059

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

2.0.0 2023-06-22 13:52 UTC

This package is auto-updated.

Last update: 2024-04-22 15:29:10 UTC


README

Latest Stable Version Total Downloads License

INSTALLATION

The preferred way to install this extension is through composer.

composer require exbico/monolog-db-bundle

Your bundle should be automatically enabled by Flex. In case you don't use Flex, you'll need to manually enable the bundle by adding the following line in the config/bundles.php file of your project:

Exbico\MonologDbBundle\ExbicoMonologDbBundle::class => ['all' => true],

CONFIGURATION

Example of config/packages/exbico_monolog_db.php with default values

<?php

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension(
        'exbico_monolog_db',
        [
            'connection'   => 'doctrine.dbal.connection',
            'levels'       => [
                /** The key-value array, where the key is the name of the level,
                 * and the value is the name of the table to save logs to.
                 * A Null value means that this level is not processed.
                 */
                'emergency' => 'log_emergency',
                'alert'     => 'log_alert',
                'critical'  => 'log_critical'
                'error'     => 'log_error',
                'warning'   => 'log_warning',
                'notice'    => 'log_notice',
                'info'      => 'log_info',
                'debug'     => 'log_debug',
            ],
            'rotation'   => [
                'history_size' => 2,
                'date_format'  => 'YmdHis',
            ],
        ],
    );
};

Example of config/packages/monolog.php

<?php

use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $containerConfigurator->extension(
        'monolog',
        [
            'handlers' => [
                'db'                => [
                    'type'     => 'service',
                    'id'       => 'exbico_monolog_db.handler',
                    'level'    => 'debug',
                ],
            ],
        ],
    );
};

USAGE

Initialize the tables

bin/console log:init

Rotate the tables

bin/console log:rotate