I am currently implementing a import console application for which it would be nice to log error messages, warnings, etc. to a log file. I tried to use Yii::log(), but it won’t write the log entries to the application.log.
I have already been digging through the Yii sources and as it seems to me console applications do not support logging at all. Am I right, or did I just forget any special config for that purpose?
Logging for console applications works just like the logging for web applications. Could you show us your config file and the usage of the Yii::log() command?
public function run($args)
{
$identity=new UserIdentity('admin','admin');
if(! $identity->authenticate())
{
echo "Error: Authentication is required to run this command";
return;
}
Yii::app()->user->login($identity);
}
I think the problem was ending the console app with "die()" instead of Yii::app()->end as logs are written when the app is shut down.
But for saving a lot memory I now would recommend completely deactivating the logging within console apps or using the new 1.1.8 release which enables logging at runtime.
I have exactly the same configuration for logroutes in config/console.php as in config/main.php (except a different filename for logFile)
However, logging from web application works, while logging from console commands doesn’t work. Nothing is logged at all. And i don’t have any die() or exit().
Also, I’m interested in how to enable this “runtime logging”. I guess that means logging immediately rather than holding log messages in memory until the end, right? How do I enable that? (obviously I wouldn’t do it for the web app but for the console app).