/** * @brief initialize the log sections * * This writes a list of all available and all enabled sections to the log. * * Log sections can be enabled using the configuration key "LogSections", * or the environment variable "SPRING_LOG_SECTIONS". * * Both specify a comma-separated list of sections that should be enabled. * The lists from both sources are combined, there is no overriding. * * A section that is enabled by default, can not be disabled. */ static void InitializeLogSections() { // the new systems (ILog.h) log-sub-systems are called sections const std::set<const char*>& registeredSections = log_filter_section_getRegisteredSet(); // enabled sections is a superset of the ones specified in the // environment and the ones specified in the configuration file. const std::map<std::string, int>& enabledSections = GetEnabledSections(); std::stringstream availableLogSectionsStr; std::stringstream enabledLogSectionsStr; availableLogSectionsStr << "Available log sections: "; enabledLogSectionsStr << "Enabled log sections: "; unsigned int numRegisteredSections = 0; unsigned int numEnabledSections = 0; for (auto si = registeredSections.begin(); si != registeredSections.end(); ++si) { numRegisteredSections++; availableLogSectionsStr << ((numRegisteredSections > 1)? ", ": ""); availableLogSectionsStr << *si; // enabled sections (keys) are in lower-case const auto sectionIter = enabledSections.find(StringToLower(*si)); // skip if section is registered but not enabled if (sectionIter == enabledSections.end()) continue; // user-specified wanted level for this section const int sectionLevel = sectionIter->second; if (sectionLevel >= LOG_LEVEL_NONE) continue; // find the nearest lower known log-level (in descending order) const int logLevel = log_util_getNearestLevel(sectionLevel); // levels can't go lower than this if (logLevel < 0) continue; log_filter_section_setMinLevel(*si, logLevel); enabledLogSectionsStr << ((numEnabledSections > 0)? ", ": ""); enabledLogSectionsStr << *si << "(" << log_util_levelToString(logLevel) << ")"; numEnabledSections++; } LOG("%s", (availableLogSectionsStr.str()).c_str()); LOG("%s", (enabledLogSectionsStr.str()).c_str()); LOG("Enable or disable log sections using the LogSections configuration key"); LOG(" or the SPRING_LOG_SECTIONS environment variable (both comma separated)."); LOG(" Use \"none\" to disable the default log sections."); }
bool CKeyBindings::ExecuteCommand(const string& line) { const vector<string> words = CSimpleParser::Tokenize(line, 2); if (words.empty()) { return false; } const string command = StringToLower(words[0]); if (command == "keydebug") { const int curLogLevel = log_filter_section_getMinLevel(LOG_SECTION_KEY_BINDINGS); bool debug = (curLogLevel == LOG_LEVEL_DEBUG); if (words.size() == 1) { // toggle debug = !debug; } else if (words.size() >= 2) { // set debug = atoi(words[1].c_str()); } if (debug && !LOG_IS_ENABLED_STATIC(L_DEBUG)) { LOG_L(L_WARNING, "You have to run a DEBUG build to be able to log L_DEBUG messages"); } log_filter_section_setMinLevel(LOG_SECTION_KEY_BINDINGS, (debug ? LOG_LEVEL_DEBUG : LOG_LEVEL_INFO)); } else if ((command == "fakemeta") && (words.size() > 1)) { if (!SetFakeMetaKey(words[1])) { return false; } } else if ((command == "keyset") && (words.size() > 2)) { if (!AddNamedKeySet(words[1], words[2])) { return false; } } else if ((command == "keysym") && (words.size() > 2)) { if (!AddKeySymbol(words[1], words[2])) { return false; } } else if ((command == "bind") && (words.size() > 2)) { if (!Bind(words[1], words[2])) { return false; } } else if ((command == "unbind") && (words.size() > 2)) { if (!UnBind(words[1], words[2])) { return false; } } else if ((command == "unbindaction") && (words.size() > 1)) { if (!UnBindAction(words[1])) { return false; } } else if ((command == "unbindkeyset") && (words.size() > 1)) { if (!UnBindKeyset(words[1])) { return false; } } else if (command == "unbindall") { bindings.clear(); keyCodes->Reset(); namedKeySets.clear(); typeBindings.clear(); Bind("enter", "chat"); // bare minimum } else { return false; } if (userCommand) { Sanitize(); } return false; }
void CLogOutput::InitializeSections() { // the new systems (ILog.h) log-sub-systems are called sections: const std::set<const char*> sections = log_filter_section_getRegisteredSet(); { std::stringstream logSectionsStr; logSectionsStr << "Available log sections: "; int numSec = 0; std::set<const char*>::const_iterator si; for (si = sections.begin(); si != sections.end(); ++si) { if (numSec > 0) { logSectionsStr << ", "; } logSectionsStr << *si; numSec++; } LOG("%s", logSectionsStr.str().c_str()); } // enabled sections is a superset of the ones specified in the environment // and the ones specified in the configuration file. // configHandler cannot be accessed here in unitsync, as it may not exist. std::string enabledSections = ","; #if defined(UNITSYNC) #if defined(DEBUG) // unitsync logging in debug mode always on enabledSections += "unitsync,ArchiveScanner,"; #endif #else #if defined(DEDICATED) enabledSections += "DedicatedServer,"; #endif #if !defined(DEBUG) // Always show at least INFO level of these sections enabledSections += "Sound,"; #endif enabledSections += StringToLower(configHandler->GetString("LogSections")) + ","; #endif const char* const envSec = getenv("SPRING_LOG_SECTIONS"); std::string env; if (envSec != NULL) { env += ","; env += envSec; } if (!env.empty()) { // this allows to disable all sections from the env var std::string envSections(StringToLower(env)); if (envSections == std::string("none")) { enabledSections = ""; } else { enabledSections += envSections + ","; } } const std::string enabledSectionsLC = StringToLower(enabledSections); { std::stringstream enabledLogSectionsStr; enabledLogSectionsStr << "Enabled log sections: "; int numSec = 0; // new log sections std::set<const char*>::const_iterator si; for (si = sections.begin(); si != sections.end(); ++si) { const std::string name = StringToLower(*si); const bool found = (enabledSectionsLC.find("," + name + ",") != std::string::npos); if (found) { if (numSec > 0) { enabledLogSectionsStr << ", "; } #if defined(DEBUG) log_filter_section_setMinLevel(*si, LOG_LEVEL_DEBUG); enabledLogSectionsStr << *si << "(LOG_LEVEL_DEBUG)"; #else // defined(DEBUG) log_filter_section_setMinLevel(*si, LOG_LEVEL_INFO); enabledLogSectionsStr << *si << "(LOG_LEVEL_INFO)"; #endif // defined(DEBUG) numSec++; } } LOG("%s", enabledLogSectionsStr.str().c_str()); } LOG("Enable or disable log sections using the LogSections configuration key"); LOG(" or the SPRING_LOG_SECTIONS environment variable (both comma separated)."); LOG(" Use \"none\" to disable the default log sections."); }