Can't logging in console application

Hi all

I tried to using log in my console app, and did not work, things like nothing happened

this is my console configure setting:




'log'=>array(

	'class'=>'CLogRouter',

	'routes'=>array(

		array(

			'class'=>'CFileLogRoute',

			'levels'=>'trace, info',

			'logFile'=>'consoleApplication.log', 

			'categories'=>'application.*',

			'maxFileSize'=>1024, 

		),

	),

),



this configure works find at web application

I also googled and find from this forum, but also can’t find out why these happened

can someone help me out? thx!

Permission problem? This tip might help.

(I think an exception would be generated, though.)

Does the console application terminate correctly.

Perhaps Yii::app()->log->processLogs() or Yii::getLogger()->flush(true) may help.

Edit: hardly a permission problem since the file name is set to consoleApplication.log ;D

/Tommy

thx for reply :)

I tried Yii::app()->log->processLogs(), it works at the moment

but can’t let console application logging all the runtime, it should not be that, right?

what does your mean?

Maybe it is the problem, below are all my testing script.

I use testing script that only echo some text and also log something, but the same result, nothing happened…

here is my testing code:




class TestCommand extends CConsoleCommand{

	

	public function actionIndex(){

		echo 'test'.PHP_EOL;

		Yii::trace('test');

	}

}



and




php console.php test



my bootstrap "console.php":




// change the following paths if necessary

$yii=dirname(__FILE__).'/../yii/framework/yii.php';

$config=dirname(__FILE__).'/protected/config/console.php';


// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


require_once($yii);

Yii::createConsoleApplication($config)->run();



did I forgot anything?

ahh…I got something, I forgot a config:




'preload'=>array('log'),



after add this configure setting, my log file works fine.

but still can’t have a runtime logging, logging message always show in the end of execution.

I hope console logging can show on any time I want in my script, any idea?

I haven’t tried but you may want to have a closer look at this.

Also search the forum for existent info.

/Tommy

sorry I’m just a newbie so yesterday cannot reply more

I got this topic from the forum:

http://www.yiiframework.com/forum/index.php?/topic/10421-logging-in-long-running-console-app/page__p__51157__hl__log+con+ole#entry51157

yeah, autoFlush is the key, and I found in 1.1.8, it has a more efficient way to have a real-time console logging architecture

here is my code, extend from CConsoleCommand:




class CLogConsoleCommand extends CConsoleCommand{

	

	public function run($args)

	{

		Yii::getLogger()->autoFlush = 1;

		Yii::getLogger()->autoDump = true;

		parent::run($args);

	}

}



it works fine to me :)

thank you Tommy, hope this will help somewhere :)