|
Boost : |
Subject: Re: [boost] Custom logging backend difficulty
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2014-10-27 16:30:09
On Monday 27 October 2014 15:48:28 Kenneth Adam Miller wrote:
> On Mon, Oct 27, 2014 at 3:03 PM, Kenneth Adam Miller <
>
> kennethadammiller_at_[hidden]> wrote:
> > Ah ok that clarifies somewhat; I thought it was the formatter that I was
> > having trouble with. I tried setting one, and then saw that the text was
> > added to the console to test. But I'm doing
> > boost::log::add_common_attributes(), and I print the string to std out
> > just
> > to make sure that I will get what I expect. As it turns out, I think that
> > the backend is supposed to visit the record_view, and the record view has
> > the default attributes and any others added.
The formatter just composes a string from the attribute values attached to the
record, it's the sink backend that is supposed to do something with that
string, like output to the console or send over the network. Text-based
backends typically don't need to access the record view (although they're
still able to) because the formatter already did all the job.
> > I'm trying to get those extra attributes; if I do BOOST_LOG(lg) << " blah"
> > << endl; I get "blah" on my screen which I swap out the backend from the
> > default. My backend just prints to the console.
> >
> > How do I had the record_view items to the string to be sent?
With formatter, you just have to use it in the formatting expression. A few
examples are here:
http://www.boost.org/doc/libs/1_56_0/libs/log/doc/html/log/tutorial/formatters.html
Basically, you need the attribute value name and type to do that.
> Reading some more at the top of this:
> http://boost-log.sourceforge.net/libs/log/doc/html/log/tutorial/formatters.h
> tml
>
> I found that:
> Even if you added attributes to the logging core or a logger, the attribute
> values will not reach the output unless you specify a formatter that will
> use these values.
>
> is what is holding me up. How can I specify a formatter that just gives the
> attribute name and then it's value, each separable by some delimiter? I
> want to make certain that all attributes are consumed. Really, the reason
> why I want this is, I don't know what the actual types are in the attr<
> some_type > format, as demonstrated in several examples. This is kind of a
> work around, but really I just want all the data that I enable at the
> consumer level to make it by some default formatting method.
There is no built-in formatter in the library that just iterates through the
values in the record, you have to write your own. It's simple, just write a
function like described here:
The record view has attribute_values() member, which returns an associative
container of all attached values in pairs (name; value). Each value is an
object of attribute_value class, from which you can extract the actual
contained value through one of the approaches listed in the link I posted
earlier. In particular, you can use visitation and something similar to a
print_visitor class in the example here:
Of course, the formatter should insert its output into the provided stream,
not std::cout.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk