/*** * We try to make log available even if errorlog is not setup. * So, at the beginning, we put the logs to StringList plainconf::errorLogList by call logToMem() * once flushErrorLog() is called, it means errorlog is setup, and this function will save all * the buffered logs to errorlog file. * Then if logToMem still be called, it should not access the stringlist anymore, * but just access the errorlog directly. */ void plainconf::logToMem(char errorLevel, const char *format, ...) { char buf[512]; sprintf(buf, "%c[PlainConf] ", errorLevel); int len = strlen(buf); if (gModuleList.size() > 0) { XmlNode *pCurNode = (XmlNode *)gModuleList.back(); sprintf(buf + len, "[%s:%s] ", pCurNode->getName(), ((pCurNode->getValue() == NULL) ? "" : pCurNode->getValue())); } len = strlen(buf); va_list ap; va_start(ap, format); int ret = vsnprintf(buf + len, 512 - len, format, ap); va_end(ap); if (!bErrorLogSetup) errorLogList.add(buf, ret + len); else { if (errorLevel == LOG_LEVEL_ERR) LS_ERROR(buf + 1); else LS_INFO(buf + 1); } }
int IpToGeo::config(const XmlNodeList *pList) { XmlNodeList::const_iterator iter; int succ = 0; for (iter = pList->begin(); iter != pList->end(); ++iter) { XmlNode *p = *iter; const char *pFile = p->getValue(); char achBufFile[MAX_PATH_LEN]; if ((!pFile) || (ConfigCtx::getCurConfigCtx()->getValidFile(achBufFile, pFile, "GeoIP DB") != 0)) continue; if (setGeoIpDbFile(achBufFile, p->getChildValue("geoipDBCache")) == 0) succ = 1; } if (succ) IpToGeo::setIpToGeo(this); else { LS_WARN(ConfigCtx::getCurConfigCtx(), "Failed to setup a valid GeoIP DB file, Geolocation is disable!"); return LS_FAIL; } return 0; }
void plainconf::appendModuleParam(XmlNode *pModuleNode, const char *param) { XmlNode *pParamNode = pModuleNode->getChild("param"); if (pParamNode == NULL) { pParamNode = new XmlNode; const char *attr = NULL; pParamNode->init("param", &attr); pParamNode->setValue(param, strlen(param)); pModuleNode->addChild(pParamNode->getName(), pParamNode); } else { AutoStr2 totalValue = pParamNode->getValue(); totalValue.append("\n", 1); totalValue.append(param, strlen(param)); pParamNode->setValue(totalValue.c_str(), totalValue.len()); } logToMem(LOG_LEVEL_INFO, "[%s:%s] module [%s] add param [%s]", pModuleNode->getParent()->getName(), ((pModuleNode->getParent()->getValue()) ? pModuleNode->getParent()->getValue() : ""), pModuleNode->getValue(), param); }