让日志携带请求标识,便于查询

浏览:247 发布日期:2020/03/10 分类:ThinkPHP6专区 关键字: 日志
一个请求会记录多条日志,当并发大的时候,如果采用的是实时记录会导致一个问题,不同的请求记录的日志会分散开,不是全部挨着的,这个时候对于排查问题很不方便,做如下改动之后就能够方便记录。
文件:\vendor\topthink\framework\src\think\Log.php
函数:recordpublic function record($msg, string $type = 'info', array $context = [], bool $lazy = true)
    {
        static $int_id=null;
        if($int_id===null){
            $int_id = rand(100000000,900000000);
        }
        $msg="[{$int_id}] ".$msg;
        $channel = $this->getConfig('type_channel.' . $type);
        $this->channel($channel)->record($msg, $type, $context, $lazy);
        return $this;
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>