cebe/yii2-loki-log-target

Grafana Loki 日志目标用于 Yii2

1.2.0 2024-06-06 14:43 UTC

This package is auto-updated.

Last update: 2024-09-06 15:06:29 UTC


README

Grafana Loki 日志目标用于 Yii2。

要求

  • PHP 7.1 或更高版本(与 PHP 8 兼容)
  • Yii 2

安装

composer require cebe/yii2-loki-log-target

用法

将日志目标添加到您的应用程序配置

// ...
'components' => [
    // ...
    'log' => [
        // ...
        'targets' => [
            [
                'class' => \cebe\lokilogtarget\LokiLogTarget::class,
                //'enabled' => YII_ENV_PROD,

                'lokiPushUrl' => 'https://loki.example.com/loki/api/v1/push',
                'lokiAuthUser' => 'loki', // HTTP Basic Auth User
                'lokiAuthPassword' => '...', // HTTP Basic Auth Password

                'levels' => ['error', 'warning', 'info'],

                // optionally exclude categories
                'except' => [
                    'yii\db\Connection::open',
                    'yii\db\Command::execute',
                    'yii\httpclient\StreamTransport::send',
                ],

                // optionally re-map log level for certain categories
                'levelMap' => [
                    // yii category
                    'yii\web\HttpException:404' => [
                        // yii level => loki level
                        // set loki level to false, to drop messages with that category
                        '*' => 'info',
                    ],
                    'yii\web\HttpException:401' => [
                        // yii level => loki level
                        // set loki level to false, to drop messages with that category
                        '*' => 'warning',
                    ],
                ],

            ],
        ],
    ],
]

请参阅此处