From: Stephen Morris Date: Wed, 10 Jul 2013 10:34:36 +0000 (+0100) Subject: [3048] Remove logging messages from some ServerHooks methods X-Git-Tag: bind10-1.2.0beta1-release~338^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fd70aa81aeebbb2768d89185d1859520cd535b58;p=thirdparty%2Fkea.git [3048] Remove logging messages from some ServerHooks methods Removing logging from the constructor and the registerHooks() method allows hooks to be registered using static initialization, where logging is not available. --- diff --git a/src/lib/hooks/hooks_messages.mes b/src/lib/hooks/hooks_messages.mes index 33c12824f9..7d13250b75 100644 --- a/src/lib/hooks/hooks_messages.mes +++ b/src/lib/hooks/hooks_messages.mes @@ -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) diff --git a/src/lib/hooks/server_hooks.cc b/src/lib/hooks/server_hooks.cc index 1a0b157377..f934eff11d 100644 --- a/src/lib/hooks/server_hooks.cc +++ b/src/lib/hooks/server_hooks.cc @@ -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. diff --git a/src/lib/hooks/server_hooks.h b/src/lib/hooks/server_hooks.h index f075cb8b8d..4b53d1482e 100644 --- a/src/lib/hooks/server_hooks.h +++ b/src/lib/hooks/server_hooks.h @@ -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 HookCollection; typedef std::map InverseHookCollection;