The Yii2 debugger seems to only work for web requests. How can I debug console commands (CLI)?
Eg. I need to see the SQL statements that were executed during a console command...
Use logger:
'log' => [
'targets' => [[
...
], [
'class' => 'yii\log\FileTarget',
'logFile' => '@runtime/logs/profile.log',
'logVars' => [],
'levels' => ['profile'],
'categories' => ['yii\db\Command::query'],
'prefix' => function($message) {
return '';
}
]]
]
'microtime' => true, helps a lot to see SQL performance problems.https://github.com/achertovsky/yii2-debug-cli
i wrote extension to existing yii2-debug to achieve the result. Please, use and lmk issues if you find some.
In the Yii2 default application advanced template, you already have the log file target setup/enabled. However, it is only enabled for 'error' and 'warning' conditions. To include for info, add info as below in the console/config/main.php
[
'class' => 'yii\log\FileTarget',
'levels' => ['info', 'error', 'warning'],
],
The log output should be in console/runtime/logs/app.log