Yii2默认日志记录到文件中,通过配置log组件来重新将日志保存到数据库中
打开config目录下console.php文件,修改log配置
‘log‘ => [ ‘targets‘ => [ [ ‘class‘ => ‘yii\log\DbTarget‘, ‘levels‘ => [‘error‘, ‘warning‘], ], ], ],
打开cmd 命令行,进入Yii根目录,开始创建数据库
yii migrate [email protected]/log/migrations/
输入yes
数据库中就会创建好log表,配置web.php文件的log的targets将日志记录到数据库中
‘log‘ => [ ‘traceLevel‘ => 0, ‘targets‘ => [ [ ‘class‘ => ‘yii\log\DbTarget‘, ‘levels‘ => [‘error‘, ‘warning‘, ‘trace‘, ‘info‘], ], ], ],
重新访问网站,查看log表:
时间: 2024-10-12 23:32:23