[ask]log in console

hello … i want to ask how to write LOG FILE to a file with a console yiic …

in config/main I wrote





'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'logFile'=>'LOGFILE',

					'logPath'=>'C:/xampp/htdocs/cbc/',

					'levels'=>'error, warning , trace',

					

				),



and runs perfectly

but in the config/console I tried the same thing but nothing happened …

how to write the log in the console?

is in DemoCommand.php need to be set again to write the log or just in config/console.php :huh:

please help me

See my article for unit testing: nikiink.wordpress.com/2012/03/19/yii-console-log-with-unit-testing/. You should create a new class that extends CLogRoute and logging to the console (using echo) in the processLogs method.

I paste my article:

Yii Console Log with Unit Testing

Posted on 19 marzo 2012

  1. install phpunit correctly

pear install phpunit/PHPUnit

pear install phpunit/PHPUnit_Selenium

  1. create the class CConsoleLogRoute in the components directory in the file CConsoleLogRoute.php with this code:

<?php

class CConsoleLogRoute extends CLogRoute {

protected function processLogs($logs)

{

foreach($logs as $log) {

echo $this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);

}

}

}

  1. configure YII to log when unit testing:

3a. add the log key in the components array in protected/config/test.php

‘log’=>array(

‘class’=>’CLogRouter’,

‘routes’=>array(

array(

‘class’=>’CConsoleLogRoute’,

‘levels’=>’error, warning, info, trace’,

),

),

),

3b. add some lines in protected/tests/bootstrap.php, the modified file should be this: (added the lines with YII_DEBUG, YII_TRACE_LEVEL, autoFlush and autoDump)

<?php

// change the following paths if necessary

$yiit=dirname(FILE).’/../../../framework/yiit.php’;

$config=dirname(FILE).’/../config/test.php’;

defined(‘YII_DEBUG’) or define(‘YII_DEBUG’,true);

defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’, 0);

require_once($yiit);

require_once(dirname(FILE).’/WebTestCase.php’);

Yii::createWebApplication($config);

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

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