/** * @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."); }
static void log_formatter_createPrefix_testing(char** buffer, size_t* bufferSize, const char* section, int level) { section = log_util_prepareSection(section); const char* levelStr = log_util_levelToString(level); SNPRINTF(*buffer, *bufferSize, "%s %s: ", levelStr, section); }
static void log_formatter_createPrefix_default(char** buffer, size_t* bufferSize, const char* section, int level) { (*buffer)[0] = '\0'; if (!LOG_SECTION_IS_DEFAULT(section)) { section = log_util_prepareSection(section); STRCAT_T(*buffer, *bufferSize, "["); STRCAT_T(*buffer, *bufferSize, section); STRCAT_T(*buffer, *bufferSize, "] "); } if (level != LOG_LEVEL_INFO) { const char* levelStr = log_util_levelToString(level); STRCAT_T(*buffer, *bufferSize, levelStr); STRCAT_T(*buffer, *bufferSize, ": "); } }