agielks / yii2-log-json
将您的yii2应用程序日志转换为json并保存到文件、redis或logstash
1.0.0
2022-07-05 08:31 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is auto-updated.
Last update: 2024-09-27 14:14:12 UTC
README
将您的yii2应用程序日志转换为json并保存到文件、redis或logstash
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist agielks/yii2-log-json "~1.0"
或将以下内容添加到您的 composer.json
文件的 require 部分中。
"agielks/yii2-log-json": "~1.0"
基本用法
文件目标
'components' => [ // ... 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'agielks\yii2\log\json\FileTarget', 'levels' => ['error', 'warning'], 'except' => [ 'yii\web\HttpException:*', ], ], ], ], // ... ],
Logstash 目标配置
'components' => [ // ... 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'agielks\yii2\log\json\LogstashTarget', 'dsn' => '127.0.0.1:5000', 'index' => 'my-index', 'type' => 'log', 'levels' => ['error', 'warning'], 'except' => [ 'yii\web\HttpException:*', ], ], ], ], // ... ],
Redis 目标配置
'components' => [ // ... // Redis connection 'redis' => [ 'class' => 'yii\redis\Connection', 'hostname' => '127.0.0.1', 'port' => 6379, 'database' => 0, ], // Redis log configuration 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'agielks\yii2\log\json\RedisTarget', 'db' => 'redis', 'levels' => ['error', 'warning'], 'except' => [ 'yii\web\HttpException:*', ], ], ], ], // ... ],