[bind10-dev] are static Logger objects safe?

Stephen Morris stephen at isc.org
Fri Jun 10 14:47:29 UTC 2011


On 10/06/2011 10:54, Michal 'vorner' Vaner wrote:
> Hello
> 
> On Thu, Jun 09, 2011 at 04:26:11PM -0700, JINMEI Tatuya / 神明達哉 wrote:
>> I've just notice there are many (namespace scope) static Logger
>> objects:
>>
>> src/bin/resolver/resolver_log.cc:isc::log::Logger resolver_logger("resolver");
>> src/lib/asiodns/io_fetch.cc:isc::log::Logger logger("asiolink");
>> ...
>>
>> In general such static objects can cause static initialization fiasco
>> very easily and should be avoided whenever possible.  Are they really
>> safe?
> 
> The documentation about the loggers suggests so, and I saw some tricks to make
> it work, but I didn't look too closely. But AFAIK they are supposed to be safe.
> 
> Stephen might know more.

They are.

The loggers are built on the "pimpl" idiom.  All the declaration does is
store the name of the logger within the object - there are no
dependencies on other objects.

The implementation class is instantiated using the stored name the first
time a method within the logger is called (which should be when
initialization has finished and the program is running).

Stephen



More information about the bind10-dev mailing list