Boost logo

Boost Users :

Subject: Re: [Boost-users] [Log] How to use?
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2010-08-20 16:04:04


2010/8/20 Oskar Nordquist <oskar.nordquist_at_[hidden]>

> 2010/8/20 Oskar Nordquist <oskar.nordquist_at_[hidden]>:
> > 2010/8/20 Olivier Tournaire <olitour_at_[hidden]>
> >>
> >> OK. However, I do not understand why this formatter (and only this one)
> >> goes out of scope. How can I move it to a global scope to avoid the
> current
> >> behavior (std::nothrow works likes a charm)?
> >
> > The macro BOOST_LOG_SCOPED_THREAD_ATTR registers an attribute at the
> current
> > scope, and unregisters it when the current scope exits. In your code,
> this
> > line is used in your class constructor:
> >
> > BOOST_LOG_SCOPED_THREAD_ATTR("Uptime", attrs::timer);
> >
> > This attribute will work for every BOOST_LOG() or BOOST_LOG_SEV() issued
> in
> > the scope where this attribute was registered. In your case, you are
> doing a
> > log message from
> the a_test_method_to_see_if_the_logger_is_still_working()
> > function. When this function is executed, the attribute is no longer in
> > scope (as the constructor is already run, hence attribute is no longer in
> > scope) and when the formatting step is done at this time, the attribute
> does
> > not exist and that is why the exception is thrown.
> > To make this attribute work everywhere you should put the line above that
> > registers the attribute in your main() function before any logging is
> done.
>
>
> On second thought, this is what you want to do:
>
> boost::log::core::get()->add_global_attribute("Uptime", attrs::timer());
>
> Put this in your constructor before any logging is done. That way you
> do not have to have any code outside your class.
>

Great! Thank you very much for your time Oskar.

Regards,

Olivier

> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net