chathurasudarsha/yii2-log-target-file

Yii 2.0 可定制日志消息文件目标

1.0.0 2018-11-07 11:49 UTC

This package is auto-updated.

Last update: 2024-09-26 18:25:36 UTC


README

定制日志消息

排序和更改日志消息的单元

安装

只需在控制台运行

composer require donsimon/yii2-log-target-file "*"

或添加

"donsimon/yii2-log-target-file": "*"

到你的 composer.json 文件的要求部分。

用法

将以下行添加到您的配置文件中(例如 config/main.php),

    'bootstrap' => ['log'],

然后,

将以下行添加到配置文件中的组件部分,

        'log' => [
        //          'traceLevel' => YII_DEBUG ? 3 : 0,
                    'targets' => [
                          [  
                                'class' => 'donsimon\log\logTargetFile',  
                                'levels' => ['info','warning','error'],
                                'categories' => ['user','application'],
                                'logVars' => ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'],
                                'logFile' => '@backend/runtime/logs/appAndUser.log',
                                'logMessageContainer' =>['timestamp','prefix','level','category','message'],
                                'prefixContainer'=>['ip','userId','sessionId']
                            ]
                    ],
        ],

要写入日志文件,客户端应调用类似以下的内容,

Yii::info($message, $category);

在这里 $message 和 $category 是变量。

您的日志将更新。

您能在这里做什么,

您可以使用 logFile 更改日志文件名。

eg: @backend/runtime/logs/user-activities.log

您可以添加多个 categories

eg: ['yii\web\HttpException:*','yii\base\ErrorException:*','user','application']

您可以添加多个 levels

eg: ['info','warning','error']

您可以使用 logVars 打印变量。

更多信息

logMessageContainer 是一个包含日志消息单元的数组 ['timestamp','prefix','level','category','message']

您可以使用 logMessageContainer 排序和更改日志消息单元。

prefixContainer 是一个包含前缀单元的数组 ['ip','userId','sessionId']

您可以使用 prefixContainer 排序和更改日志消息前缀。