Boost logo

Boost :

Subject: Re: [boost] [log] v2 Initialisation, default sink behaviour and filtering documentation
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-01-27 06:10:57


Sorry for the delay, I somehow forgot about this email.

On Friday 25 January 2013 08:44:01 Mats Taraldsvik wrote:
> Hi Andrey,
>
> I found the reason for having to call remove_all_sinks repeatedly : I was
> initializing multiple logger objects repeatedly, thus adding the sinks to
> the core multiple times. Unfortunately, I can't avoid this. Is there a
> better workaround than creating a custom core attribute telling me whether
> the core has been initialized?

I take it that you are initializing the library while initializing a global
logger the first time, is that right? If so, then you probably should move all
library initialization code (including addition of sinks and attributes to the
core) to an external function and protect it with call_once, once blocks or
another similar mechanism. Then you will be able to invoke it multiple times
for different global loggers without reinitializing the core.

> Ok. I understood that the severity_level is allowed to be a custom object.
> What I did not understand in this context was how to filter the object
> representing the severity (for trivial::severity it was the object e.g.
> trivial::fatal, but the advanced documentation compared against an int (I
> am aware that enums are implicitly casted to ints, but still)).

The code sample in the sinks description is not related to trivial logging,
and actually the filter itself is not important in that example. For clarity,
if the filter extracts an int, like in that example, it won't work with other
types, so the example assumes that the logger is also using int for severity
levels. You can see it in the complete code of the example.

> New question:
>
> I can't get this (or BOOST_LOG_SCOPED_THREAD_ATTR) to compile:
>
> BOOST_LOG_SCOPED_LOGGER_ATTR(_logger, "FID",
> boost::log::attributes::constant<int>(id));
>
> _logger is a private member reference to a severity_logger
>
> Compile errors (more or less equal for BOOST_LOG_SCOPED_THREAD_ATTR):
>
> 1>Object.cpp(945): error C2248:
> 'boost::log::v2s_mt_nt5::aux::scoped_logger_attribute<LoggerT>::scoped_logg
> er_attribute' : cannot access private member declared in class
> 'boost::log::v2s_mt_nt5::aux::scoped_logger_attribute<LoggerT>' 1>
> with
> 1> [
> 1>
> LoggerT=boost::log::v2s_mt_nt5::sources::severity_logger<boost::log::v2s_mt
> _nt5::trivial::severity_level> 1> ]
> 1> boost/log/attributes/scoped_attribute.hpp(58) : see declaration
> of
> 'boost::log::v2s_mt_nt5::aux::scoped_logger_attribute<LoggerT>::scoped_logg
> er_attribute' 1> with
> 1> [
> 1>
> LoggerT=boost::log::v2s_mt_nt5::sources::severity_logger<boost::log::v2s_mt
> _nt5::trivial::severity_level> 1> ]

I think I've fixed this in trunk.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk