Log4Php & Yii

Hi,

if you would like to use log4php logging library with Yii (much better than Log library in Yii), this code might be helpful:

  1. Copy log4php sources to protected/vendors/log4php

  2. Add application.vendors.* to config import




return array(

	...

	'import'=>array(

		'application.models.*',

		'application.components.*',	

		'application.vendors.*',

	),

	...

);



  1. Unregister yii autoload, require log4php (register log4php autoload), register yii autoload in index.php



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

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

require_once($yii);


$app = Yii::createWebApplication($config);


spl_autoload_unregister(array('YiiBase','autoload')); 

require_once('log4php/Logger.php'); // require registers Logger autoload

spl_autoload_register(array('YiiBase','autoload'));


$app->run();



  1. Use Logger



$logger = Logger::getLogger('');

$logger->info('It works');



its working no error…bt where log file is created ???? cant find log file