BIND 10 trac1004, updated. 935bd760ed4f39213f8db8eab730bf41dc217da9 [trac1004] ignore unrelated logger configs

BIND 10 source code commits bind10-changes at lists.isc.org
Fri Jun 24 17:24:30 UTC 2011


The branch, trac1004 has been updated
       via  935bd760ed4f39213f8db8eab730bf41dc217da9 (commit)
      from  78cffeb00933814658da0867ada0209403946b51 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 935bd760ed4f39213f8db8eab730bf41dc217da9
Author: Jelte Jansen <jelte at isc.org>
Date:   Fri Jun 24 19:21:21 2011 +0200

    [trac1004] ignore unrelated logger configs
    
    and only replace '*' if there is no logger explicitely configured for the expanded name

-----------------------------------------------------------------------

Summary of changes:
 src/lib/config/ccsession.cc |   73 ++++++++++++++++++++++++++++++++++++-------
 1 files changed, 61 insertions(+), 12 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/config/ccsession.cc b/src/lib/config/ccsession.cc
index 4ff2780..43f5c58 100644
--- a/src/lib/config/ccsession.cc
+++ b/src/lib/config/ccsession.cc
@@ -216,17 +216,6 @@ readLoggersConf(std::vector<isc::log::LoggerSpecification>& specs,
 {
     std::string lname = logger->get("name")->stringValue();
 
-    // If the first part of the name is '*', it is meant for 'every
-    // program', so we replace it with whatever is set as the root
-    // logger.
-    // We could tokenize the string, but if * is used, the string
-    // should either be "*", or start with "*.", so it's easier to
-    // look directly
-    if (lname.length() > 0 && lname[0] == '*' &&
-        (lname.length() == 1 || lname[1] == '.')) {
-        lname = isc::log::getRootLoggerName() + lname.substr(1);
-    }
-
     ConstElementPtr severity_el = getValueOrDefault(logger,
                                       "severity", config_data,
                                       "loggers/severity");
@@ -257,6 +246,65 @@ readLoggersConf(std::vector<isc::log::LoggerSpecification>& specs,
     specs.push_back(logger_spec);
 }
 
+
+// Returns the loggers related to this module
+//
+// This function does two things;
+// - it drops the configuration parts for loggers for other modules
+// - it replaces the '*' in the name of the loggers by the name of
+//   this module, but *only* if the expanded name is not configured
+//   explicitely
+//
+// Examples: if this is the module b10-resolver,
+// For the config names ['*', 'b10-auth']
+// The '*' is replaced with 'b10-resolver', and this logger is used.
+// 'b10-auth' is ignored (of course, it will not be in the b10-auth
+// module).
+//
+// For ['*', 'b10-resolver']
+// The '*' is ignored, and only 'b10-resolver' is used.
+//
+// For ['*.reslib', 'b10-resolver']
+// Or ['b10-resolver.reslib', '*']
+// Both are used, where the * will be expanded to b10-resolver
+//
+// \param The original 'loggers' config list
+// \returns ListElement containing only loggers relevant for this
+//          module, where * is replaced by the root logger name
+ConstElementPtr
+getRelatedLoggers(ConstElementPtr loggers) {
+    // Keep a list of names for easier lookup later
+    std::vector<std::string> our_names;
+    const std::string& root_name = isc::log::getRootLoggerName();
+
+    ElementPtr result = isc::data::Element::createList();
+
+    BOOST_FOREACH(ConstElementPtr cur_logger, loggers->listValue()) {
+        const std::string cur_name = cur_logger->get("name")->stringValue();
+        if (cur_name.find(root_name) == 0) {
+            our_names.push_back(cur_name);
+            result->add(cur_logger);
+        }
+    }
+
+    // now find the * names
+    BOOST_FOREACH(ConstElementPtr cur_logger, loggers->listValue()) {
+        std::string cur_name = cur_logger->get("name")->stringValue();
+        // if name starts with *, replace * with root logger name
+        if (cur_name.length() > 0 && cur_name[0] == '*') {
+            cur_name = root_name + cur_name.substr(1);
+
+            // now add it to the result list, but only if a logger with
+            // that name was not configured explicitely
+            if (std::find(our_names.begin(), our_names.end(),
+                          cur_name) != our_names.end()) {
+                result->add(cur_logger);
+            }
+        }
+    }
+    return result;
+}
+
 } // end anonymous namespace
 
 void
@@ -268,8 +316,9 @@ default_logconfig_handler(const std::string& module_name,
     std::vector<isc::log::LoggerSpecification> specs;
 
     if (new_config->contains("loggers")) {
+        ConstElementPtr loggers = getRelatedLoggers(new_config->get("loggers"));
         BOOST_FOREACH(ConstElementPtr logger,
-                      new_config->get("loggers")->listValue()) {
+                      loggers->listValue()) {
             readLoggersConf(specs, logger, config_data);
         }
     }




More information about the bind10-changes mailing list