Boost logo

Boost Users :

Subject: Re: [Boost-users] [Log] How to use?
From: Oskar Nordquist (oskar.nordquist_at_[hidden])
Date: 2010-08-20 15:30:34

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.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at