static void onConfig(const ConfigSection& section, bool isDryRun, const std::string&) { // log // { // ; default_level specifies the logging level for modules // ; that are not explicitly named. All debugging levels // ; listed above the selected value are enabled. // // default_level INFO // // ; You may also override the default for specific modules: // // FibManager DEBUG // Forwarder WARN // } auto defaultLevel = ndn::util::LogLevel::INFO; auto item = section.get_child_optional("default_level"); if (item) { defaultLevel = parseLogLevel(*item, "default_level"); } if (!isDryRun) { // default_level applies only to NFD loggers ndn::util::Logging::setLevel("nfd.*", defaultLevel); } for (const auto& i : section) { if (i.first == "default_level") { // do nothing } else { auto level = parseLogLevel(i.second, i.first); if (!isDryRun) { if (i.first.find('.') == std::string::npos) // backward compat: assume unqualified logger names refer to NFD loggers ndn::util::Logging::setLevel("nfd." + i.first, level); else ndn::util::Logging::setLevel(i.first, level); } } } }
void Logging::setLevelImpl(const std::string& config) { std::stringstream ss(config); std::string configModule; while (std::getline(ss, configModule, ':')) { size_t ind = configModule.find('='); if (ind == std::string::npos) { BOOST_THROW_EXCEPTION(std::invalid_argument("malformed logging config: '=' is missing")); } std::string moduleName = configModule.substr(0, ind); LogLevel level = parseLogLevel(configModule.substr(ind + 1)); this->setLevelImpl(moduleName, level); } }
void TraceDebug::parsePass1() { char buf[200]; char *str = buf; int tabIndex = 0; int inputFileLine = 0; while(fgets (str, sizeof(buf), fd) != NULL) if (tabIndex < LOG_TABLE_NB_ENTRIES) { // get nb tabs int pos = 0; while( (str[pos] == '\t' )&& (str[pos] != '\0') ) pos++; str += pos; // go forward // file pointer (for debug purpose) inputFileLine++; // get tags if (str[0] == '[') { char * token; token = strtok(str, "]"); if(token && token[0] == '[' ) { _tableLevel[tabIndex].indent = pos; strncpy(_tableLevel[tabIndex].tag,token,LOG_TABLE_TAG_LENGTH); token = strtok(NULL, "]"); // go forward } // get level _tableLevel[tabIndex].logLevel = parseLogLevel(token); tabIndex++; } } else { printf("<!--Too many entries in file %s, ligne %d ignored:'%s')--> \n", LOG_CNF_FILE, __LINE__, str); } }
void Logger::setLogLevel(const std::string& level) { gLogLevel = parseLogLevel(level); }
void Configuration::parse(std::string fileName) { std::ifstream infile(fileName); // check if file exists if (not infile.good()) { infile.close(); throw ConfigurationException( ConfigurationException::Type::NO_CONFIG_FILE); } Json::Value root; Json::Reader reader; bool parseOK = reader.parse(infile, root, false); if (not parseOK) { std::string details = reader.getFormattedErrorMessages(); ConfigurationException configurationException( ConfigurationException::Type::CONFIG_FILE_SYNTAX_ERROR); configurationException.setDescription(details); infile.close(); throw configurationException; } if (not root["httpServer"]["address"].empty()) this->httpServerAddress = root["httpServer"]["address"].asString(); else { ConfigurationException exception = ConfigurationException( ConfigurationException::Type::INCOMPLETE_CONFIG_FILE); exception.setDescription( "httpServer.address not provided in config file"); throw exception; } if (not root["httpServer"]["port"].empty()) this->httpServerPort = root["httpServer"]["port"].asInt(); else { ConfigurationException exception = ConfigurationException( ConfigurationException::Type::INCOMPLETE_CONFIG_FILE); exception.setDescription("httpServer.port not provided in config file"); throw exception; } if (not root["httpServer"]["readTimeout"].empty()) this->httpServerReadTimeout = root["httpServer"]["readTimeout"].asInt(); else { ConfigurationException exception = ConfigurationException( ConfigurationException::Type::INCOMPLETE_CONFIG_FILE); exception.setDescription( "httpServer.readTimeout not provided in config file"); throw exception; } if (not root["httpServer"]["maxThreads"].empty()) this->httpServerMaxThreads = root["httpServer"]["maxThreads"].asInt(); else { ConfigurationException exception = ConfigurationException( ConfigurationException::Type::INCOMPLETE_CONFIG_FILE); exception.setDescription( "httpServer.maxThreads not provided in config file"); throw exception; } if (not root["dnsPooler"]["interval"].empty()) this->dnsPoolerInterval = root["dnsPooler"]["interval"].asInt(); else { ConfigurationException exception = ConfigurationException( ConfigurationException::Type::INCOMPLETE_CONFIG_FILE); exception.setDescription( "dnsPooler.interval not provided in config file"); throw exception; } parseLogLevel(root); this->readyToUse = true; }