1

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...

3 Answers 3

2

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 '';
    }
]]

]

Sign up to request clarification or add additional context in comments.

1 Comment

One more attribute 'microtime' => true, helps a lot to see SQL performance problems.
0

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.