The Yii logging format is great for the frontend in that it automatically tracks the user in the userID field. Works great. However, in console commands and when sending work to a service layer or queue, e.g., yii2-queue, there is no “user”.
So for those jobs I have to take care to always add a line such as “USER=X” in the log output.
Is there a better way?
My thinking was that every service could simply Yii::$app->user->setIdentity($user). Is this standard practice or is this frowned upon?
It would completely solve the logging issue when running work through the console and service layer/queues/etc.
Any input on best practices or potential issues is appreciated!