|
Boost : |
Subject: Re: [boost] [log] v2 Initialisation, default sink behaviour and filtering documentation
From: Mats Taraldsvik (mats.taraldsvik_at_[hidden])
Date: 2013-02-08 02:53:32
Hi Andrey,
Sorry for the late reply.
> -----Opprinnelig melding-----
> Fra: Boost [mailto:boost-bounces_at_[hidden]] På vegne av Andrey
> Semashev
> Sendt: 27. januar 2013 12:11
> Til: boost_at_[hidden]
> Emne: Re: [boost] [log] v2 Initialisation, default sink behaviour and filtering
> documentation
>
> 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.
>
Unfortunately, no. I'm implementing a new module called by a legacy interface, and don't know the number of instances of that interface present at a given time (probably, it will be limited to one, but in my test code at least, multiple instances exist). Each interface therefore has its own logger object, and the initialization of this object, along with the initialization of backends/sinks/core, happens at construction of the interface object.
Currently I'm calling remove_all_sinks, and this works well. Another approach, that you suggest, would be a static once_flag member for the interface, and call_once for the backends/sink/core initialization. The latter introduces some complexity, and the former is not ideal. I think I'll try to avoid the complexity if the remove_all_sinks approach does not cause any issues..
> > 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.
>
If you could include exactly that paragraph in the docs, when you move from trivial::severity_level to int, that would make things clearer :)
> > 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
> > 1> declaration
> > of
> >
> 'boost::log::v2s_mt_nt5::aux::scoped_logger_attribute<LoggerT>::scoped_lo
> gg
> > 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.
>
Brilliant, thanks! Works very well. :)
As a side note, I'm extremely satisfied with the library. Thanks for developing it! :)
Regards
Mats Taraldsvik
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk