N
N
Natalia2016-11-08 16:37:32
Yii
Natalia, 2016-11-08 16:37:32

How to enable console command logging in Yii2?

I am developing a controller that will be launched by cron. Accordingly, the controller is console and information about requests to this controller is not logged in Yii Debugger.
In console.php config:

'bootstrap' => ['log', 'gii','debug'],
    'controllerNamespace' => 'app\commands',
    'modules' => [
        'gii' => 'yii\gii\Module',
        'debug' => [
            'class' => 'yii\debug\Module',
            'allowedIPs' => ['*'],
        ],
    ],

The main goal is to see a list of queries to the database, and since. in the list of requests in Yii Debugger there is no request to the console controller - I can not do this

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Natalia, 2016-11-09
@Hatysik

Because for me, logging console controllers was necessary to determine what data to load through ->with, the solution turned out to be the following:
after executing a request to the database, I hang up a handler on the ActiveRecord::EVENT_AFTER_FIND event and look at the objects of which classes are taken from the database after the request is executed. This is how I determine which links are not yet specified in ->with

Event::on(ActiveRecord::className(), ActiveRecord::EVENT_AFTER_FIND, function (Event $event) {
   echo $event->sender->className()."\n";
});

A
Andrey Pavlenko, 2016-11-08
@Akdmeh

As far as I remember, this is unfortunately not possible in console mode.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question