让错误日志显示当前连接的数据库信息

浏览:1292 发布日期:2015/10/23 分类:功能实现 关键字: 分布式 读写分离 主从数据库 错误信息
在数据库分布式部署环境下,TP的错误Trace机制并不会显示是哪个数据库有问题,当我们进行排查的时候,有可能就其中某一台不正常,这时,我们就很难进行排查了,此方法将可以解决此问题。
在数据库分布式部署环境下,TP的错误Trace机制并不会显示是哪个数据库有问题,当我们进行排查的时候,有可能就其中某一台不正常,这时,我们就很难进行排查了,此方法将可以解决此问题。
找到文件:
./ThinkPHP/Library/Think/Db/Driver.class.php
第57行插入    // 数据库当前连接参数配置
    protected $_config = array();
第97行插入            // 数据库当前连接参数配置
            $this->_config = $config;
第110行将                if($autoConnection){
                    trace($e->getMessage(),'','ERR');
                    return $this->connect($autoConnection,$linkNum);
                }elseif($config['debug']){
                    E($e->getMessage());
                }
替换成                // 输出当前数据库连接信息
                $message =  $e->getMessage() . "\n [ 当前链接 ] : ".$this->_config['database'].'@'.$this->_config['hostname'].':'.$this->_config['hostport'];
                if($autoConnection){
                    trace($message,'','ERR');
                    return $this->connect($autoConnection,$linkNum);
                }elseif($config['debug']){
                    E($message);
                }
第345行插入        // 输出当前数据库连接信息
        $this->error .= "\n [ 当前链接 ] : ".$this->_config['database'].'@'.$this->_config['hostname'].':'.$this->_config['hostport'];
评论( 相关
后面还有条评论,点击查看>>