Server IP : 103.233.192.212 / Your IP : 18.191.37.16 Web Server : Apache/2 System : Linux sv1.inde.co.th 3.10.0-1160.36.2.el7.x86_64 #1 SMP Wed Jul 21 11:57:15 UTC 2021 x86_64 User : sumpatuan ( 1058) PHP Version : 5.5.38 Disable Function : symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,putenv,passthru,escapeshellarg,escapeshellcmd,pcntl_exec,proc_get_status,proc_nice,proc_terminate,pclose,ini_alter,virtual,openlog,ini_restore MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/sumpatuan/public_html/backup/framework/logging/ |
Upload File : |
<?php /** * CDbLogRoute class file. * * @author Qiang Xue <qiang.xue@gmail.com> * @link http://www.yiiframework.com/ * @copyright 2008-2013 Yii Software LLC * @license http://www.yiiframework.com/license/ */ /** * CDbLogRoute stores log messages in a database table. * * To specify the database table for storing log messages, set {@link logTableName} as * the name of the table and specify {@link connectionID} to be the ID of a {@link CDbConnection} * application component. If they are not set, a SQLite3 database named 'log-YiiVersion.db' will be created * and used under the application runtime directory. * * @author Qiang Xue <qiang.xue@gmail.com> * @package system.logging * @since 1.0 */ class CDbLogRoute extends CLogRoute { /** * @var string the ID of CDbConnection application component. If not set, a SQLite database * will be automatically created and used. The SQLite database file is * <code>protected/runtime/log-YiiVersion.db</code>. */ public $connectionID; /** * @var string the name of the DB table that stores log content. Defaults to 'YiiLog'. * If {@link autoCreateLogTable} is false and you want to create the DB table manually by yourself, * you need to make sure the DB table is of the following structure: * <pre> * ( * id INTEGER NOT NULL PRIMARY KEY, * level VARCHAR(128), * category VARCHAR(128), * logtime INTEGER, * message TEXT * ) * </pre> * Note, the 'id' column must be created as an auto-incremental column. * In MySQL, this means it should be <code>id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY</code>; * In PostgreSQL, it is <code>id SERIAL PRIMARY KEY</code>. * @see autoCreateLogTable */ public $logTableName='YiiLog'; /** * @var boolean whether the log DB table should be automatically created if not exists. Defaults to true. * @see logTableName */ public $autoCreateLogTable=true; /** * @var CDbConnection the DB connection instance */ private $_db; /** * Initializes the route. * This method is invoked after the route is created by the route manager. */ public function init() { parent::init(); if($this->autoCreateLogTable) { $db=$this->getDbConnection(); try { $db->createCommand()->delete($this->logTableName,'0=1'); } catch(Exception $e) { $this->createLogTable($db,$this->logTableName); } } } /** * Creates the DB table for storing log messages. * @param CDbConnection $db the database connection * @param string $tableName the name of the table to be created */ protected function createLogTable($db,$tableName) { $db->createCommand()->createTable($tableName, array( 'id'=>'pk', 'level'=>'varchar(128)', 'category'=>'varchar(128)', 'logtime'=>'integer', 'message'=>'text', )); } /** * @return CDbConnection the DB connection instance * @throws CException if {@link connectionID} does not point to a valid application component. */ protected function getDbConnection() { if($this->_db!==null) return $this->_db; elseif(($id=$this->connectionID)!==null) { if(($this->_db=Yii::app()->getComponent($id)) instanceof CDbConnection) return $this->_db; else throw new CException(Yii::t('yii','CDbLogRoute.connectionID "{id}" does not point to a valid CDbConnection application component.', array('{id}'=>$id))); } else { $dbFile=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'log-'.Yii::getVersion().'.db'; return $this->_db=new CDbConnection('sqlite:'.$dbFile); } } /** * Stores log messages into database. * @param array $logs list of log messages */ protected function processLogs($logs) { $command=$this->getDbConnection()->createCommand(); foreach($logs as $log) { $command->insert($this->logTableName,array( 'level'=>$log[1], 'category'=>$log[2], 'logtime'=>(int)$log[3], 'message'=>$log[0], )); } } }