Home > PHP Framework > ThinkPHP > body text

How to solve the problem that ThinkPHP6.0 logs are not output to files

WBOY
Release: 2023-05-31 22:37:04
forward
1757 people have browsed it

Problem description

Output a log in TP6

use think\facade\Log;

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

Obviously the default output configured in config/log.php is file, others The code is also used normally

It is used in the exception handling fileapp/ExceptionHandle.php. I want to output the error message to the file to facilitate debugging and find bugs

Log::error($e);
Copy after login

It is output directly to The output stream is returned to the front end

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

Causes json parsing to fail

Problem solution

Just convert the exception object into a string

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

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

The above is the detailed content of How to solve the problem that ThinkPHP6.0 logs are not output to files. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!