ThinkPHP6.0日志没有输出到文件而是直接输出到了输出流

问题描述

TP6中输出一条日志

use think\facade\Log;

Log.debug("这是一条日志")

明明config/log.php 里配置的默认输出就是 file,其他代码使用也正常

在异常处理文件app/ExceptionHandle.php 中使用,想将错误信息输出到文件,方便调试找bug

Log::error($e);

直接输出到了输出流,返回给了前端

{
    
    code: -1, msg: '错误', data: null}{
    
    }

导致json解析失败

问题解决

将异常对象转为字符串就可以了

Log::error($e->getTraceAsString());

// 或者指定输出通道
Log::channel('file')->error('一条测试日志');

文档:https://www.kancloud.cn/manual/thinkphp6_0/1037616

猜你喜欢

转载自blog.csdn.net/mouday/article/details/127125443