private function testFile() { $logFile = LogBase::getFile()->setType(LogBase::TYPE_DAEMON)->setIdentify('Up201405')->add('Find some thing wrong.'); //支持批量插入 需要同一个日志实例 $logFile->add('Find 1 thing wrong.'); $logFile->add('Find 2 thing wrong.'); $logFile->add('sorry, db falied', TRUE); $logFile->add('sorry, db falied'); $logFile->add('sorry, db falied'); }
/** * 获取日志对象 */ protected function getLog() { if ($this->logInstance !== NULL) { return $this->logInstance; } if (!static::LOG_SERVICE || preg_match('/[^\\w]/is', static::LOG_SERVICE)) { throw new \Exception("static::LOG_SERVICE 无效。"); } $this->logInstance = LogBase::getFile()->setIdentify(static::LOG_SERVICE)->setType(LogBase::TYPE_DAEMON); return $this->logInstance; }
protected function __construct($config) { $driverConfig = empty($config['driver']) ? '' : Front::getInstance()->getAppConfig()->getByKey($config['driver']); if (empty($config['driver']) || empty($driverConfig)) { throw new \HuiLib\Error\Exception('Log mysql driver ini error'); } $this->driver = DbBase::create($driverConfig); if (!$this->driver instanceof \HuiLib\Db\Adapter\Pdo\PdoBase) { throw new \HuiLib\Error\Exception('Log mysql driver initialized failed'); } if (empty($config['table'])) { throw new \HuiLib\Error\Exception('Log mysql driver table ini error'); } $this->table = $config['table']; parent::__construct($config); }
/** * 获取日志对象 */ protected function getLog() { if ($this->logInstance !== NULL) { return $this->logInstance; } $this->logInstance = LogBase::getFile()->setIdentify($this->service)->setType(LogBase::TYPE_DAEMON); return $this->logInstance; }
public function __destruct() { parent::__destruct(); if ($this->fileFd) { fclose($this->fileFd); } }
* * @since 2013/11/10 * * Log支持储存后端:File, Mysql, Mongo * * 适配器接口: * add($info):添加一条日志信息 */ use HuiLib\Log\LogBase; //快速获取一个Apc Log实例 $cache = LogBase::getMysql(); //快速获取一个File Log缓存实例 $cache = LogBase::getFile(); //快速获取一个Memcache Log缓存实例 $cache = LogBase::getMongo(); //File完整示例 支持批量保存多条,但必须在同个log实例 $log = LogBase::getFile(); $log->setType(LogBase::TYPE_USERERROR); $log->setIdentify('PHPFrameTest'); //会放置到文件名中作为区分 $log->add('sorry, db falied'); $log->add('sorry, db falied'); $log->add('sorry, db falied'); //Mysql完整示例 支持批量保存多条,但必须在同个log实例 //2014-05-25.Up201405.Runtime.log $log = LogBase::getMysql(); $log->setType(LogBase::TYPE_USERERROR); $log->setIdentify('PHPFrameTest'); $log->add('sorry, db falied'); $log->add('sorry, db falied'); $log->add('sorry, db falied');