Yii Framework Forum: Log4Php & Yii - Yii Framework Forum

Jump to content

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

Log4Php & Yii Use log4php logging library in Yii Rate Topic: -----

#1 User is offline   neovmt 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-September 12

Posted 27 September 2012 - 04:41 PM

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.*',
	),
	...
);


3. 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();


4. Use Logger
$logger = Logger::getLogger('');
$logger->info('It works');

1

#2 User is offline   Chintan Chiku 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 20-March 14

Posted 26 March 2014 - 01:28 AM

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

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