'Yii2: How do I debug console commands?
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...
Solution 1:[1]
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 '';
}
]]
]
Solution 2:[2]
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.
Solution 3:[3]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | uldis |
Solution 2 | Alexander Chertovsky |
Solution 3 | Senthil |