exbico/monolog-db-bundle

Symfony MonologDb Bundle

安装数: 1,209

依赖: 0

建议: 0

安全: 0

星星: 0

关注者: 2

分支: 1

开放问题: 0

类型:symfony-bundle

2.0.1 2024-06-13 11:27 UTC

This package is auto-updated.

Last update: 2024-09-13 12:01:39 UTC


README

Latest Stable Version Total Downloads License

安装

安装此扩展的首选方式是通过composer

composer require exbico/monolog-db-bundle

您的捆绑包应该会由Flex自动启用。如果您不使用Flex,您需要手动通过在项目的config/bundles.php文件中添加以下行来启用捆绑包

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

配置

config/packages/exbico_monolog_db.php的示例,使用默认值

<?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',
            ],
        ],
    );
};

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',
                ],
            ],
        ],
    );
};

用法

初始化表

bin/console log:init

旋转表

bin/console log:rotate