thinkphp6:配置应⽤的⽇志(thinkphp6.0.5php7.4.9)⼀,指定⽇志的级别和⽂件路径
修改config/log.php
设置两项:
//指定⽇志的级别,
//默认的级别:debug, info, notice, warning, error, critical, alert, emergency,sql
'level'        => ['error','critical', 'alert', 'emergency','warning'],
//指定⽇志的⽬录:
// ⽇志保存⽬录
'path'          => '/data/logs/phplogs/tlog',
效果如下:
<?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,
// ⽇志通道列表
'channels'    => [
'file' => [
// ⽇志记录⽅式
'type'          => 'File',
// ⽇志保存⽬录
'path'          => '/data/logs/phplogs/tlog',
/
/ 单⽂件⽇志写⼊
'single'        => false,
// 独⽴⽇志级别
'apart_level'    => [],
// 最⼤⽇志⽂件数量
'max_files'      => 0,
// 使⽤JSON格式记录
'json'          => false,
// ⽇志处理
'processor'      => null,
// 关闭通道⽇志写⼊
'close'          => false,
// ⽇志输出格式化
'format'        => '[%s][%s] %s',
// 是否实时写⼊
'realtime_write' => false,
],
// 其它⽇志通道配置
],
];
说明:刘宏缔的架构森林是⼀个专注架构的博客,地址:
对应的源码可以访问这⾥获取:
说明:作者:刘宏缔邮箱: 371125307@qq
⼆,测试效果:
在⼀个controller中中加上除0的代码,然后进⾏访问:
127.0.0.1:81/adm
查看⽇志:
liuhongdi@ku:/data/logs/phplogs/tlog/202012$ more 24.log
[2020-12-24T14:45:11+08:00][error] [2]Division by zero[/data/php/mytp/app/adm/controller/Index.php:11]
php8兼容php7吗三,如何设置记录发⽣错误时的堆栈信息?
修改config/log.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'          => '/data/logs/phplogs/tlog',
// 单⽂件⽇志写⼊
'single'        => false,
// 独⽴⽇志级别
'apart_level'    => [],
// 最⼤⽇志⽂件数量
'max_files'      => 0,
/
/ 使⽤JSON格式记录
'json'          => false,
// ⽇志处理
'processor'      => null,
// 关闭通道⽇志写⼊
'close'          => false,
// ⽇志输出格式化
'format'        => '[%s][%s] %s',
// 是否实时写⼊
'realtime_write' => false,
],
/
/ 其它⽇志通道配置
],
];
四,测试效果:
访问写有除0错代码的url:
127.0.0.1:81/adm
查看⽇志:
liuhongdi@ku:/data/logs/phplogs/tlog/202012$ more24.log
[2020-12-24T14:45:11+08:00][error] [2]Division by zero[/data/php/mytp/app/adm/controller/Index.php:11]
[2020-12-24T14:50:48+08:00][error] [2]Division by zero[/data/php/mytp/app/adm/controller/Index.php:11]
#0 /data/php/mytp/app/adm/controller/Index.php(11): think\initializer\Error->appError()
#1 [internal function]: app\adm\controller\Index->index()
#2 /data/php/mytp/vendor/topthink/framework/src/think/Container.php(343): ReflectionMethod->invokeArgs()
#3 /data/php/mytp/vendor/topthink/framework/src/think/route/dispatch/Controller.php(110): think\Container->invokeReflectMethod()
#4 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(59): think\route\dispatch\Controller->think\route\dispatch\{closure}() #5 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#6 /data/php/mytp/vendor/topthink/framework/src/think/route/dispatch/Controller.php(113): think\Pipeline->then()
#7 /data/php/mytp/vendor/topthink/framework/src/think/route/Dispatch.php(89): think\route\dispatch\Controller->exec()
#8 /data/php/mytp/vendor/topthink/framework/src/think/Route.php(772): think\route\Dispatch->run()
#9 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(59): think\Route->think\{closure}()
#10 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#11 /data/php/mytp/vendor/topthink/framework/src/think/Route.php(773): think\Pipeline->then()
#12 /data/php/mytp/vendor/topthink/framework/src/think/Http.php(216): think\Route->dispatch()
#13 /data/php/mytp/vendor/topthink/framework/src/think/Http.php(206): think\Http->dispatchToRoute()
#14 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(59): think\Http->think\{closure}()
#15 /data/php/mytp/vendor/topthink/think-multi-app/src/MultiApp.php(71): think\Pipeline->think\{closure}()
#16 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(59): think\app\MultiApp->think\app\{closure}()
#17 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#18 /data/php/mytp/vendor/topthink/think-multi-app/src/MultiApp.php(72): think\Pipeline->then()
#19 [internal function]: think\app\MultiApp->handle()
#20 /data/php/mytp/vendor/topthink/framework/src/think/Middleware.php(142): call_user_func()
#21 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(85): think\Middleware->think\{closure}()
#22 /data/php/mytp/vendor/topthink/think-trace/src/TraceDebug.php(71): think\Pipeline->think\{closure}()
#23 [internal function]: think\trace\TraceDebug->handle()
#24 /data/php/mytp/vendor/topthink/framework/src/think/Middleware.php(142): call_user_func()
#25 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(85): think\Middleware->think\{closure}()
#26 /data/php/mytp/vendor/topthink/framework/src/think/Pipeline.php(66): think\Pipeline->think\{closure}()
#27 /data/php/mytp/vendor/topthink/framework/src/think/Http.php(207): think\Pipeline->then()
#28 /data/php/mytp/vendor/topthink/framework/src/think/Http.php(170): think\Http->runWithRequest()
#29 /data/php/mytp/public/index.php(20): think\Http->run()
#30 {main}
五,查看thinkphp的版本
liuhongdi@ku:/data/php/mytp$ php think version
v6.0.5
六,查看php的版本:
liuhongdi@ku:/data/logs/phplogs/tlog/202012$ php --version
PHP 7.4.9 (cli) (built: Oct 26202015:17:14) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。