[bind10-dev] consider log4cplus for logging

Stephen Morris stephen at isc.org
Tue May 3 13:29:12 UTC 2011

On 28/04/2011 09:51, Michal 'vorner' Vaner wrote:
> Hello
> On Thu, Apr 28, 2011 at 09:28:27AM +0100, Stephen Morris wrote:
>> I think the way to go is template member functions, within which the
>> arguments are converted to strings through boost::lexical_cast.
>> Of course, we wouldn't have the variadic functions but if we were to
>> assume that no function call would take more than five arguments (say)
>> we could overloaded versions of the output methods (info(), error()
>> etc.) for 0, 1, ... 5 arguments. (We can't supply defaults for template
>> arguments in method definitions.)  Tedious to write, but it should be
>> relatively easy to do.
> That would be possible. One another thing is similar to the Qt .arg thing. We
> could return a temporary object from the info(), etc, which would have the
> .arg() template function with one parameter and would replace another parameter.
> Then, when the object would be destroyed, it would log. That would be less
> tedious to write, but maybe harder to understand the code.

That is possible, but what does concern me is the cost of a logging call
when no output is produced.  For example, if we have the call:

logger.debug(dbglevel, MSG_DEBUGMSG, expensive_function());

... where "expensive_function()" is some function that takes some time
to run, expensive_function() is called every time the statement is
executed, even if debugging is disabled. (This applies to logging calls
for all severity levels, but especially to debug logging which is (a)
most likely to be turned off and (b) is likely to include more
information that may be expensive to extract.)

The logger has a set of methods "isXxxxEnabled()", so the effect can be
mitigated by something like:

if (logger.isDebugEnabled()) {
    logger.debug(dbglevel, MSG_DEBUGMSG, expensive_function());

although this gets unwieldy if there are a number of logging statements
in the code.  We try to avoid macros - AFAIK, "isc_throw" is the only
macro in the BIND 10 code - but is this a case where we should define
some? For example:

    if ((LOGGER).isDebugEnabled()) { \
        (LOGGER).debug((DBGLEVEL), (ID), (ARG1)); \



More information about the bind10-dev mailing list