/** * 增加一条日志信息 * * @param string $message * @param bool $trace 是否添加调试信息 */ public function add($message, $isTrace = TRUE) { $logInfo = array('log' => $message); if ($isTrace) { $trace = self::getDebugTrace(2); //过滤两级 if (!empty($trace)) { //保留最近一条执行路径 $logInfo['trace'] = array_shift($trace); } } $logInstance = SystemLog::create()->createRow(); $logInstance['UrlNow'] = Param::getRequestUrl(); $logInstance['Type'] = $this->type; $logInstance['Identify'] = $this->identify; $logInstance['Info'] = json_encode($logInfo); $request = Front::getInstance()->getRequest(); $logInstance['Package'] = $request->getPackageRouteSeg(); $logInstance['Control'] = $request->getControllerRouteSeg(); $logInstance['Action'] = $request->getActionRouteSeg(); $logInstance['Uid'] = $this->getLoginUid(); $logInstance['CreateTime'] = DateTime::format(); $this->buffer[] = $logInstance; $this->iter++; //超出缓存允许长度、超出缓存生命期输出到磁盘 if ($this->needFulsh()) { $this->flush(); } return $this; }