Yii2默認日志記錄到文件中,通過配置log組件來重新將日志保存到數據庫中
打開config目錄下console.php文件,修改log配置
'log' => [
'targets' => [
[
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning'],
],
],
],
打開cmd 命令行,進入Yii根目錄,開始創建數據庫
yii migrate --migrationPath=@yii/log/migrations/
輸入yes

數據庫中就會創建好log表,配置web.php文件的log的targets將日志記錄到數據庫中
'log' => [
'traceLevel' => 0,
'targets' => [
[
'class' => 'yii\log\DbTarget',
'levels' => ['error', 'warning', 'trace', 'info'],
],
],
],
重新訪問網站,查看log表:

