Boost logo

Boost Users :

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


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

> 2010/8/20 Olivier Tournaire <olitour_at_[hidden]>
>
>> Thank you Oskar!
>>
>> 2010/8/20 Oskar Nordquist <oskar.nordquist_at_[hidden]>
>>
>>> 2010/8/20 Olivier Tournaire <olitour_at_[hidden]>
>>>
>>> 2010/8/20 Oskar Nordquist <oskar.nordquist_at_[hidden]>
>>>>
>>>> Hi,
>>>>>
>>>>> Just a wild guess:
>>>>>
>>>>> Since the difference between your test program and the Boost example is
>>>>> that you are doing all the preparations in the constructor, whilst Boost
>>>>> example has everything in the main() scope. My guess is something goes out
>>>>> of scope at the end of the constructor, and some attribute is unregistered
>>>>> and thus generates "missing attribute" exception.
>>>>>
>>>>
>>>> Maybe it is a problem with the singleton? No one experienced such a
>>>> problem?
>>>> I tried a really simple program found in the documentation (
>>>> http://boost-log.sourceforge.net/libs/log/doc/html/log/detailed/attributes.html#log.detailed.attributes.timer)
>>>> which uses a class. The result is the same: it throws the same exception in
>>>> the destructor.
>>>>
>>>
>>>
>>> I tried it on MSVC 10 as well and it throws the same exception. I even
>>> did a boolean formatter checking if the attribute exists:
>>>
>>> backend->set_formatter(
>>> fmt::stream
>>> << fmt::if_(flt::has_attr("Duration"))
>>> [
>>> fmt::stream << "Duration: " << fmt::attr("Duration")
>>> ]
>>> << "\tMsg: " << fmt::message());
>>>
>>> Still throws the same exception.
>>>
>>> I switched the attribute to a attrs::counter<int> and it works as
>>> expected.
>>>
>>> Seems like attrs::timer is broken!
>>>
>>
>> Seems you are right. Commenting the line
>>
>> << "] [" << fmt::time_duration< boost::posix_time::time_duration >("Uptime")
>>
>> makes the sample work.
>> Should a bug report be open?
>>
>
> Ah, sorry. I did not realize one had to use fmt::time_duration<> to print
> an attrs::timer.
>
> There is nothing wrong with attrs::timer. The problem you are having in
> your example is you are using a scoped thread attribute ("Uptime"). This
> attribute goes out of scope in your constructor, which throws the exception,
> as the value is not present in your test function.
>
>
> The manual says:
>
> It is possible that in run time the attribute value requested by the
> formatter is not present in the formatted log record. In this case the
> formatter by default will throw an exception. If this behavior is not
> desired, one can change it in one of the following ways:
>
> 1. Use the conditional formatter with the has_attr filter to first
> verify that the required attribute value is present and apply formatting
> then.
> 2. Use an additional last std::nothrow argument to the attr placeholder.
> In this case the formatter will produce no output for the missing attribute
> value, without throwing the exception.
>
>
>
> In your test program, either move the scoped attribute to your outer scope,
> use a conditional formatter, or use std::nothrow in your format attribute.
>

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)?

Regards,

Olivier

>
> For std::nothrow, use this line instead:
>
> << "] [" << fmt::time_duration< boost::posix_time::time_duration >("Uptime", std::nothrow)
>
>
>
>
>>
>> Regards,
>>
>> Olivier
>>
>>
>
> Regards,
> Oskar
>
>
> _______________________________________________
> 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