]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[3048] Remove logging messages from some ServerHooks methods
authorStephen Morris <stephen@isc.org>
Wed, 10 Jul 2013 10:34:36 +0000 (11:34 +0100)
committerStephen Morris <stephen@isc.org>
Wed, 10 Jul 2013 10:34:36 +0000 (11:34 +0100)
Removing logging from the constructor and the registerHooks() method
allows hooks to be registered using static initialization, where
logging is not available.

src/lib/hooks/hooks_messages.mes
src/lib/hooks/server_hooks.cc
src/lib/hooks/server_hooks.h

index 33c12824f949b6bf188c366c5ce8802d5313ac10..7d13250b759f068c4c43b0f5cab346f20d973bef 100644 (file)
@@ -124,11 +124,6 @@ function, but without the services offered by the library.
 This is a debug message, output when a library (whose index in the list
 of libraries (being) loaded is given) registers a callout.
 
-% HOOKS_HOOK_REGISTERED hook %1 was registered
-This is a debug message indicating that a hook of the specified name
-was registered by a BIND 10 server.  The server doing the logging is
-indicated by the full name of the logger used to log this message.
-
 % HOOKS_STD_CALLOUT_REGISTERED hooks library %1 registered standard callout for hook %2 at address %3
 This is a debug message, output when the library loading function has
 located a standard callout (a callout with the same name as a hook point)
index 1a0b157377cba5793dd93aecfe5d09d4c837af66..f934eff11dd9dd8c828973a7b9deaad5e1a4960c 100644 (file)
@@ -27,9 +27,18 @@ namespace hooks {
 
 // Constructor - register the pre-defined hooks and check that the indexes
 // assigned to them are as expected.
+//
+// Note that there are no logging messages here or in registerHooks().  One
+// method to initialize hook names is to use static initialization.  Here,
+// a static object is declared in a file outside of any function or method.
+// As a result, it is instantiated and its constructor run before the main
+// program starts.  By putting calls to ServerHooks::registerHook() in there,
+// hooks names are already registered when the program runs.  However, at that
+// point, the logging system is not initialized, so messages are unable to
+// be output.
 
 ServerHooks::ServerHooks() {
-    reset();
+    initialize();
 }
 
 // Register a hook.  The index assigned to the hook is the current number
@@ -54,17 +63,14 @@ ServerHooks::registerHook(const string& name) {
     // Element was inserted, so add to the inverse hooks collection.
     inverse_hooks_[index] = name;
 
-    // Log it if debug is enabled
-    LOG_DEBUG(hooks_logger, HOOKS_DBG_TRACE, HOOKS_HOOK_REGISTERED).arg(name);
-
     // ... and return numeric index.
     return (index);
 }
 
-// Reset ServerHooks object to initial state.
+// Set ServerHooks object to initial state.
 
 void
-ServerHooks::reset() {
+ServerHooks::initialize() {
 
     // Clear out the name->index and index->name maps.
     hooks_.clear();
@@ -82,6 +88,15 @@ ServerHooks::reset() {
                   ". context_destroy: expected = " << CONTEXT_DESTROY <<
                   ", actual = " << destroy);
     }
+}
+
+// Reset ServerHooks object to initial state.
+
+void
+ServerHooks::reset() {
+
+    // Clear all hooks then initialize the pre-defined ones.
+    initialize();
 
     // Log a warning - although this is done during testing, it should never be
     // seen in a production system.
index f075cb8b8d833017c6e844ed017f615a7a19e1a7..4b53d1482e74dda812d6eb65b704440fb33d1372 100644 (file)
@@ -74,8 +74,8 @@ public:
     ///
     /// Resets the collection of hooks to the initial state, with just the
     /// context_create and context_destroy hooks set.  This used during
-    /// construction. It is also used during testing to reset the global
-    /// ServerHooks object.
+    /// testing to reset the global ServerHooks object; it should never be
+    /// used in production.
     ///
     /// @throws isc::Unexpected if the registration of the pre-defined hooks
     ///         fails in some way.
@@ -157,6 +157,16 @@ private:
     ///         fails in some way.
     ServerHooks();
 
+    /// @brief Initialize hooks
+    ///
+    /// Sets the collection of hooks to the initial state, with just the
+    /// context_create and context_destroy hooks set.  This used during
+    /// construction.
+    ///
+    /// @throws isc::Unexpected if the registration of the pre-defined hooks
+    ///         fails in some way.
+    void initialize();
+
     /// Useful typedefs.
     typedef std::map<std::string, int> HookCollection;
     typedef std::map<int, std::string> InverseHookCollection;