B
B
buranich2014-02-03 12:57:45
Yii
buranich, 2014-02-03 12:57:45

Yii::log() not working in RabbitMQ worker body?

Hello!
I ran into a problem when calling the Yii::log() function in the body of the callback function of the RabbitMQ worker.
I write like this:

$callback = function($msg) {
    Yii::log('Log me please', 'error', 'application');
};
$channel->basic_consume('task_queue', '', false, true, false, false, $callback);

and the logs are empty.
If you call the function outside the body of the callback function, then the log is written. In other words, the log routing is configured correctly.
I also noticed that if you stop the execution of the script in the body of the callback function, then the log will be written:
$callback = function($msg) {
    Yii::log('Log me please', 'error', 'application');
    exit; // лог появился!
};
$channel->basic_consume('task_queue', '', false, true, false, false, $callback);

From this I conclude that there is some kind of buffering of the logs, which are written only at the end of the script. And you need to write in real time, because the worker never completes its work.
I would be grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
buranich, 2014-02-03
@buranich

Indeed, there is log buffering. Therefore, in order to immediately write the log, you need to do this:

Yii::log('Log me please', 'error', 'application');
Yii::getLogger()->flush(true);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question