Edit config/web.php
First log to open
' Bootstrap ' = [ ' log ' ],
[File]
' Components ' and [ ' log ' = ' = ' targets ' and ' = ' [ ' class ' = ' Yii\log\filetarget ', ' Exportinterval ' = 1,],], ,
Default output to Runtime/logs/app.log
Note the webserver or console user must have permission to write to the file
[Database]
' Log ' = = [' targets ' = [' class ' = ' yii\log\dbtarget ', ' levels ' and ' = ' error ', ' warning ', ' Trace '], []] ,
The default output DB component corresponds to the database under the {{%log}} table
Run the following command in the root directory of YII2 to generate the corresponding table schema
./yii Migrate--migrationpath=[email protected]/log/migrations/
Note that the same configuration as the web.php is config/console.php, otherwise the command execution is unsuccessful.
You can also configure different logging modes depending on the environment
' Components ' = [ ' log ' = ' = ' traceLevel ' = ' = ' dev '? 3:0, ' targets ' and ' = [' C Lass ' = ' yii\log\dbtarget ', ' levels ' and yii_debug? [' Error ', ' Warning ', ' Trace ']: [' Error '], [ ' class ' = ' Yii\log\filetarget ', ' levels ' = Yii_debug? [' Error ', ' Warning ', ' Trace ']: [' Error ', ' warning '],],],],
Yii2 log output to file and database