Yii Framework Forum: CDbLogRoute extend - Yii Framework Forum

Jump to content

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

CDbLogRoute extend CDbLogRoute Rate Topic: -----

#1 User is offline   paskuale 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 311
  • Joined: 30-December 11
  • Location:Italy, Bari

Posted 05 July 2012 - 04:42 AM

Hi all, how can extend CDbLogRoute class for add custom string in log events ? Actually I split a single string (message param)separated by comma :(

thanks
0

#2 User is offline   ikary 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 27-February 12

Posted 16 July 2012 - 06:33 AM

the fundamental problem in my case is that there is no property Autodump and autoflush in clogroute, only in Clogger

this is only an example:


class ELog extends CDbLogRoute {
	

protected function createLogTable($db,$tableName) {

		parent::createLogTable($db,$tableName);
		
		$sql="
ALTER TABLE $tableName
ADD datetime timestamp default CURRENT_TIMESTAMP,
ADD text TEXT default NULL,
ADD type VARCHAR(10) default NULL,
ADD value VARCHAR(50) default NULL,
ADD id_user int(11) default NULL,
ADD ip VARCHAR(13) default NULL,
ADD lang VARCHAR(5) default NULL,
ADD httpinfo VARCHAR(255),
ADD ishtml tinyint(1) unsigned default '0'
";
		$db->createCommand($sql)->execute();
	}

	
	
	protected function processLogs($logs)
	{	
		$sql="
INSERT INTO {$this->logTableName}
(level, category, logtime, message, ip, httpinfo, type, text, id_user, value) VALUES
(:level, :category, :logtime, :message, :ip, :httpinfo, :type, :text, :id_user, :value)
";
		
		$command=$this->getDbConnection()->createCommand($sql);
		foreach($logs as $log)
		{
			$command->bindValue(':level',$log[1]);
			$command->bindValue(':category',$log[2]);
			$command->bindValue(':logtime',(int)$log[3]);
			$command->bindValue(':message',$log[0]);
			
			//personalized fields
			$command->bindValue(':ip', 		$this->getrealip());
			$command->bindValue(':httpinfo',	$this->gethttpinfo());
			$command->bindValue(':id_user',		Yii::app()->user->getId());
			
			$elog=CJSON::decode($log[0]);
			$command->bindValue(':type',	(!isset($elog['type'])?null:$elog['type']));
			$command->bindValue(':text',	(!isset($elog['text'])?null:$elog['text']));
			$command->bindValue(':value',	(!isset($elog['value'])?null:$elog['value']));
			$command->execute();
		}
	}
	



in config/main.php

'log'=>array(
			'class'=>'CLogRouter',
			'routes'=>array(
				array(
					'class'=>'application.components.ELog',
					'levels'=>'elog',				
					'connectionID'=>'db',
					'logTableName'=>'yii_logs',
					'autoCreateLogTable'=>true,
				),
									
			),
		),



in your code:


Yii::log('this is a test', 'elog');

Yii::log(CJSON::encode(array('type'=>'neworder', 'text'=>'order nºxxxx succesfully saved', 'value'=>'xxxx')), 'elog');

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