xincheng/yii-trace

yii log append trace id

v1.0.0 2024-07-18 07:37 UTC

This package is auto-updated.

Last update: 2024-10-23 09:48:18 UTC


README

使用

安装

    
composer require xincheng/yii-trace

配置

main.php

    use Xincheng\YiiTrace\Bootstrap;
        
    [
        'bootstrap'  => [Bootstrap::class],
        ...
    ]
log.php 

    'traceLevel' => YII_DEBUG ? 3 : 0,
    'targets' => [
        [
            'class'       => 'yii\log\FileTarget',
            'levels'      => ['error', 'warning', 'info'],
            ...
            'prefix'      => function ($message) {
                return sprintf('[%s]', Yii::$app->params['trace_id']);
            }
        ],
    ]

获取TraceId

echo Yii::$app->params['trace_id'];

echo Yii::$app->traceId->getTraceId();

使用外部TraceId

header里需要设置: x-request-id

日志示例

2024-07-16 15:48:41 [36fb958d-3c5d-2928-a8be-2f77b2e50d8a][info][backend\modules\v1\service\base\OrderStrategyService::getShipping]