From c9ef773da00b6278ee2caf0d047642f523e9bfa1 Mon Sep 17 00:00:00 2001 From: Henning Koehler Date: Sat, 26 Aug 2017 14:06:47 +1200 Subject: [PATCH] fixed logging after rebase --- include/vstd/CLoggerBase.h | 1 + lib/CModHandler.cpp | 14 +++----------- lib/CSkillHandler.cpp | 28 ++++++++++++++++++---------- lib/CSkillHandler.h | 1 + lib/logging/CLogger.cpp | 1 + 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/vstd/CLoggerBase.h b/include/vstd/CLoggerBase.h index e548d0407..0c5ad7f10 100644 --- a/include/vstd/CLoggerBase.h +++ b/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 * logAi; extern DLL_LINKAGE vstd::CLoggerBase * logAnim; +extern DLL_LINKAGE vstd::CLoggerBase * logMod; diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index bddf5ee23..c3e0018ff 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -207,7 +207,7 @@ void CIdentifierStorage::registerObject(std::string scope, std::string type, std std::pair mapping = std::make_pair(fullID, data); 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); } } @@ -377,7 +377,6 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali if (!modInfo.patches.isNull()) JsonUtils::merge(modInfo.modData, modInfo.patches); - CLogger * logger = CLogger::getLogger(CLoggerDomain("mod")); for(auto & entry : modInfo.modData.Struct()) { const std::string & name = entry.first; @@ -390,7 +389,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali 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); performValidate(originalData[index],name); handler->loadObject(modName, name, originalData[index], index); @@ -398,14 +397,7 @@ bool CContentHandler::ContentTypeHandler::loadMod(std::string modName, bool vali } else { - // trace only name field of original data - I miss list comprehension - std::vector 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); handler->loadObject(modName, name, data, index); } diff --git a/lib/CSkillHandler.cpp b/lib/CSkillHandler.cpp index 713c5bb90..4423973d0 100644 --- a/lib/CSkillHandler.cpp +++ b/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) { - 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) { - 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 @@ -123,7 +136,7 @@ CSkill * CSkillHandler::loadFromJson(const JsonNode & json, const std::string & if(!skill) { - logGlobal->errorStream() << "unknown secondary skill " << identifier; + logGlobal->error("unknown secondary skill %s", identifier); 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(); 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; } @@ -180,10 +192,6 @@ void CSkillHandler::loadObject(std::string scope, std::string name, const JsonNo 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) diff --git a/lib/CSkillHandler.h b/lib/CSkillHandler.h index 628841ecf..ff4f9bcfd 100644 --- a/lib/CSkillHandler.h +++ b/lib/CSkillHandler.h @@ -45,6 +45,7 @@ public: void setDescription(const std::string & desc, int level); const std::vector> & getBonus(int level) const; const std::string & getDescription(int level) const; + std::string toString() const; SecondarySkill id; std::string identifier; diff --git a/lib/logging/CLogger.cpp b/lib/logging/CLogger.cpp index 2d32d191c..c10b2a277 100644 --- a/lib/logging/CLogger.cpp +++ b/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 * logAi = CLogger::getLogger(CLoggerDomain("ai")); DLL_LINKAGE vstd::CLoggerBase * logAnim = CLogger::getLogger(CLoggerDomain("animation")); +DLL_LINKAGE vstd::CLoggerBase * logMod = CLogger::getLogger(CLoggerDomain("mod")); CLogger * CLogger::getLogger(const CLoggerDomain & domain) {