thanks
Page 1 of 1
CDbLogRoute extend CDbLogRoute
#1
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
thanks
#2
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:
in config/main.php
in your code:
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');
Share this topic:
Page 1 of 1

Help












