一:开启记录堆栈信息
在/config/app.php,添加一行:
‘record_trace’ => true
<?php
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => env('log.channel', 'file'),
// 日志记录级别
//debug, info, notice, warning, error, critical, alert, emergency,sql
'level' => ['error','critical', 'alert', 'emergency','warning'],
// 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [],
// 关闭全局日志写入
'close' => false,
// 全局日志处理 支持闭包
'processor' => null,
//记录堆栈信息
'record_trace' => true,
// 日志通道列表
'channels' => [
'file' => [
// 日志记录方式
'type' => 'File',
// 日志保存目录
'path' => '',
// 单文件日志写入
'single' => false,
// 独立日志级别
'apart_level' => [],
// 最大日志文件数量
'max_files' => 0,
// 使用JSON格式记录
'json' => false,
// 日志处理
'processor' => null,
// 关闭通道日志写入
'close' => false,
// 日志输出格式化
'format' => '[%s][%s] %s',
// 是否实时写入
'realtime_write' => false,
],
// 其它日志通道配置
],
];
二、查看日志
admin@kus: Creating default object from empty value
[2023-03-09T14:45:11+08:00][error] [62]Division by zero[/www/wwwroot/demo/app/admin/controller/Index.php:11]
[2023-03-09T14:50:48+08:00][error] [62]Division by zero[/www/wwwroot/demo/app/admin/controller/Index.php:11]
#0 /www/wwwroot/demo/app/admin/controller/Index.php(11): think\initializer\Error->appError()
#1 [internal function]: app\admin\controller\Index->index()
#2 /www/wwwroot/demo/vendor/topthink/framework/src/think/Container.php(343): ReflectionMethod->invokeArgs()
#3 /www/wwwroot/demo/vendor/topthink/framework/src/think/route/dispatch/Controller.php(110): think\Container->invokeReflectMethod()
#4 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(59): think\route\dispatch\Controller->think\route\dispatch\{closure}()
#5 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#6 /www/wwwroot/demo/vendor/topthink/framework/src/think/route/dispatch/Controller.php(113): think\Pipeline->then()
#7 /www/wwwroot/demo/vendor/topthink/framework/src/think/route/Dispatch.php(89): think\route\dispatch\Controller->exec()
#8 /www/wwwroot/demo/vendor/topthink/framework/src/think/Route.php(772): think\route\Dispatch->run()
#9 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(59): think\Route->think\{closure}()
#10 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#11 /www/wwwroot/demo/vendor/topthink/framework/src/think/Route.php(773): think\Pipeline->then()
#12 /www/wwwroot/demo/vendor/topthink/framework/src/think/Http.php(216): think\Route->dispatch()
#13 /www/wwwroot/demo/vendor/topthink/framework/src/think/Http.php(206): think\Http->dispatchToRoute()
#14 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(59): think\Http->think\{closure}()
#15 /www/wwwroot/demo/vendor/topthink/think-multi-app/src/MultiApp.php(71): think\Pipeline->think\{closure}()
#16 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(59): think\app\MultiApp->think\app\{closure}()
#17 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#18 /www/wwwroot/demo/vendor/topthink/think-multi-app/src/MultiApp.php(72): think\Pipeline->then()
#19 [internal function]: think\app\MultiApp->handle()
#20 /www/wwwroot/demo/vendor/topthink/framework/src/think/Middleware.php(142): call_user_func()
#21 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(85): think\Middleware->think\{closure}()
#22 /www/wwwroot/demo/vendor/topthink/think-trace/src/TraceDebug.php(71): think\Pipeline->think\{closure}()
#23 [internal function]: think\trace\TraceDebug->handle()
#24 /www/wwwroot/demo/vendor/topthink/framework/src/think/Middleware.php(142): call_user_func()
#25 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(85): think\Middleware->think\{closure}()
#26 /www/wwwroot/demo/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#27 /www/wwwroot/demo/vendor/topthink/framework/src/think/Http.php(207): think\Pipeline->then()
#28 /www/wwwroot/demo/vendor/topthink/framework/src/think/Http.php(170): think\Http->runWithRequest()
#29 /www/wwwroot/demo/public/index.php(20): think\Http->run()
#30 {main}
完