浏览代码

fixed logging after rebase

Henning Koehler 8 年之前
父节点
当前提交
c9ef773da0
共有 5 个文件被更改,包括 24 次插入21 次删除
  1. 1 0
      include/vstd/CLoggerBase.h
  2. 3 11
      lib/CModHandler.cpp
  3. 18 10
      lib/CSkillHandler.cpp
  4. 1 0
      lib/CSkillHandler.h
  5. 1 0
      lib/logging/CLogger.cpp

+ 1 - 0
include/vstd/CLoggerBase.h

@@ -190,3 +190,4 @@ extern DLL_LINKAGE vstd::CLoggerBase * logBonus;
 extern DLL_LINKAGE vstd::CLoggerBase * logNetwork;
 extern DLL_LINKAGE vstd::CLoggerBase * logNetwork;
 extern DLL_LINKAGE vstd::CLoggerBase * logAi;
 extern DLL_LINKAGE vstd::CLoggerBase * logAi;
 extern DLL_LINKAGE vstd::CLoggerBase * logAnim;
 extern DLL_LINKAGE vstd::CLoggerBase * logAnim;
+extern DLL_LINKAGE vstd::CLoggerBase * logMod;

+ 3 - 11
lib/CModHandler.cpp

@@ -207,7 +207,7 @@ void CIdentifierStorage::registerObject(std::string scope, std::string type, std
 	std::pair<const std::string, ObjectData> mapping = std::make_pair(fullID, data);
 	std::pair<const std::string, ObjectData> mapping = std::make_pair(fullID, data);
 	if(!vstd::containsMapping(registeredObjects, mapping))
 	if(!vstd::containsMapping(registeredObjects, mapping))
 	{
 	{
-		CLogger::getLogger(CLoggerDomain("identifier"))->traceStream() << "registered " << fullID << " as " << scope << ":" << identifier;
+		logMod->trace("registered %s as %s:%s", fullID, scope, identifier);
 		registeredObjects.insert(mapping);
 		registeredObjects.insert(mapping);
 	}
 	}
 }
 }
@@ -377,7 +377,6 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
 	if (!modInfo.patches.isNull())
 	if (!modInfo.patches.isNull())
 		JsonUtils::merge(modInfo.modData, modInfo.patches);
 		JsonUtils::merge(modInfo.modData, modInfo.patches);
 
 
-	CLogger * logger = CLogger::getLogger(CLoggerDomain("mod"));
 	for(auto & entry : modInfo.modData.Struct())
 	for(auto & entry : modInfo.modData.Struct())
 	{
 	{
 		const std::string & name = entry.first;
 		const std::string & name = entry.first;
@@ -390,7 +389,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
 
 
 			if (originalData.size() > index)
 			if (originalData.size() > index)
 			{
 			{
-				logger->traceStream() << "found original data in loadMod(" << name << ") at index " << index;
+				logMod->trace("found original data in loadMod(%s) at index %d", name, index);
 				JsonUtils::merge(originalData[index], data);
 				JsonUtils::merge(originalData[index], data);
 				performValidate(originalData[index],name);
 				performValidate(originalData[index],name);
 				handler->loadObject(modName, name, originalData[index], index);
 				handler->loadObject(modName, name, originalData[index], index);
@@ -398,14 +397,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali
 			}
 			}
 			else
 			else
 			{
 			{
-				// trace only name field of original data - I miss list comprehension
-				std::vector<std::string> originalNames;
-				for (const JsonNode & orgElem : originalData)
-					originalNames.push_back(orgElem["name"].String());
-				logger->debugStream() << "no original data in loadMod(" << name << ") at index " << index;
-				logger->traceStream() << "originalData: " << originalNames;
-				logger->traceStream() << "new data: " << data;
-
+				logMod->debug("no original data in loadMod(%s) at index %d", name, index);
 				performValidate(data, name);
 				performValidate(data, name);
 				handler->loadObject(modName, name, data, index);
 				handler->loadObject(modName, name, data, index);
 			}
 			}

+ 18 - 10
lib/CSkillHandler.cpp

@@ -76,12 +76,25 @@ const std::string & CSkill::getDescription(int level) const
 
 
 DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info)
 DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill::LevelInfo &info)
 {
 {
-    return out << "(\"" << info.description << "\"," << info.effects << ")";
+    out << "(\"" << info.description << "\", [";
+    for(int i=0; i < info.effects.size(); i++)
+        out << (i ? "," : "") << info.effects[i]->Description();
+    return out << "])";
 }
 }
 
 
 DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill &skill)
 DLL_LINKAGE std::ostream & operator<<(std::ostream &out, const CSkill &skill)
 {
 {
-    return out << "Skill(" << (int)skill.id << "," << skill.identifier << "): " << skill.levels;
+    out << "Skill(" << (int)skill.id << "," << skill.identifier << "): [";
+    for(int i=0; i < skill.levels.size(); i++)
+        out << (i ? "," : "") << skill.levels[i];
+    return out << "]";
+}
+
+std::string CSkill::toString() const
+{
+	std::ostringstream ss;
+	ss << *this;
+	return ss.str();
 }
 }
 
 
 ///CSkillHandler
 ///CSkillHandler
@@ -123,7 +136,7 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
 
 
     if(!skill)
     if(!skill)
     {
     {
-        logGlobal->errorStream() << "unknown secondary skill " << identifier;
+        logGlobal->error("unknown secondary skill %s", identifier);
         throw std::runtime_error("invalid skill");
         throw std::runtime_error("invalid skill");
     }
     }
 
 
@@ -143,9 +156,8 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string &
             //CGI->generaltexth->skillInfoTexts[skill->id][level-1] = levelNode["description"].String();
             //CGI->generaltexth->skillInfoTexts[skill->id][level-1] = levelNode["description"].String();
             skill->setDescription(levelNode["description"].String(), level);
             skill->setDescription(levelNode["description"].String(), level);
     }
     }
-    CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
-    logger->debugStream() << "loaded secondary skill " << identifier << "(" << (int)skill->id << ")";
-    logger->traceStream() << *skill;
+    logMod->debug("loaded secondary skill %s(%d)", identifier, (int)skill->id);
+    logMod->trace("%s", skill->toString());
 
 
     return skill;
     return skill;
 }
 }
@@ -180,10 +192,6 @@ void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNo
 
 
 void CSkillHandler::afterLoadFinalization()
 void CSkillHandler::afterLoadFinalization()
 {
 {
-    CLogger * logger = CLogger::getLogger(CLoggerDomain(getTypeName()));
-    logger->traceStream() << "skill handler after load: ";
-    for(auto skill : objects)
-        logger->traceStream() << *skill;
 }
 }
 
 
 void CSkillHandler::beforeValidate(JsonNode & object)
 void CSkillHandler::beforeValidate(JsonNode & object)

+ 1 - 0
lib/CSkillHandler.h

@@ -45,6 +45,7 @@ public:
     void setDescription(const std::string & desc, int level);
     void setDescription(const std::string & desc, int level);
     const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
     const std::vector<std::shared_ptr<Bonus>> & getBonus(int level) const;
     const std::string & getDescription(int level) const;
     const std::string & getDescription(int level) const;
+    std::string toString() const;
 
 
     SecondarySkill id;
     SecondarySkill id;
     std::string identifier;
     std::string identifier;

+ 1 - 0
lib/logging/CLogger.cpp

@@ -83,6 +83,7 @@ DLL_LINKAGE vstd::CLoggerBase * logBonus = CLogger::getLogger(CLoggerDomain("bon
 DLL_LINKAGE vstd::CLoggerBase * logNetwork = CLogger::getLogger(CLoggerDomain("network"));
 DLL_LINKAGE vstd::CLoggerBase * logNetwork = CLogger::getLogger(CLoggerDomain("network"));
 DLL_LINKAGE vstd::CLoggerBase * logAi = CLogger::getLogger(CLoggerDomain("ai"));
 DLL_LINKAGE vstd::CLoggerBase * logAi = CLogger::getLogger(CLoggerDomain("ai"));
 DLL_LINKAGE vstd::CLoggerBase * logAnim = CLogger::getLogger(CLoggerDomain("animation"));
 DLL_LINKAGE vstd::CLoggerBase * logAnim = CLogger::getLogger(CLoggerDomain("animation"));
+DLL_LINKAGE vstd::CLoggerBase * logMod = CLogger::getLogger(CLoggerDomain("mod"));
 
 
 CLogger * CLogger::getLogger(const CLoggerDomain & domain)
 CLogger * CLogger::getLogger(const CLoggerDomain & domain)
 {
 {