alan/yii2-monolog

There is no license information available for the latest version (v1.0.3) of this package.

yii2 framwork use monolog library

v1.0.3 2020-09-27 06:26 UTC

This package is auto-updated.

Last update: 2024-10-27 16:04:17 UTC


README

  1. 安装

    composer require alan/yii2-monolog

  2. 配置

    'log' => [
                'traceLevel' => YII_DEBUG ? 3 : 0,
                'flushInterval' => 10,
                'targets' => [
                    [
                        'class' => 'common\log\MonologComponent',
                        'levels' => ['error', 'warning', 'info', 'trace', 'profile'],
                        'except' => [
                            'yii\base\*',
                        ],
                        'exportInterval' => 1,
                        'logVars' => [],
                        'channels' => [
                            'main' => [
                                'handler' => [
                                    [
                                        'class' => 'Monolog\Handler\StreamHandler',
                                        'stream' => '@app/runtime/logs/log_' . date('Y-m-d') . '.log',
                                        'level' => 'debug',
                                        'formatter' => [
                                            'class' => 'Monolog\Formatter\LogstashFormatter',
                                            'applicationName' => 'shanghu-backend',
                                            'systemName' => 'shanghu-test',
                                        ],
                                    ],
                                ],
                                'processor' => [
                                    \yii2\monolog\LogIdProcessor::instance(), //生成logId
                                ],
                            ],
                        ],
                    ]
                ],
            ],
  3. 日志写入无变更

  4. 如在控制台使用则需要手动刷新logId,手动调用如何方法

    \yii2\monolog\LogIdProcessor::instance()->refresh();