Yii Framework Forum: Can't logging in console application - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Can't logging in console application Rate Topic: -----

#1 User is offline   Taker 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 09-September 11

Posted 09 September 2011 - 05:01 AM

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!
0

#2 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 09 September 2011 - 05:15 AM

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

This post has been edited by tri: 09 September 2011 - 05:51 AM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#3 User is offline   Taker 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 09-September 11

Posted 09 September 2011 - 09:01 AM

View Posttri, on 09 September 2011 - 05:15 AM, said:

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?

Quote

Does the console application terminate correctly.

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?
0

#4 User is offline   Taker 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 09-September 11

Posted 09 September 2011 - 09:21 AM

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?
0

#5 User is online   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 09 September 2011 - 09:27 AM

View PostTaker, on 09 September 2011 - 09:21 AM, said:

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
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#6 User is offline   Taker 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 09-September 11

Posted 10 September 2011 - 10:21 AM

View Posttri, on 09 September 2011 - 09:27 AM, said:

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.yiiframew...+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 :)
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users