Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2008-08-20 12:38:31


Boris wrote:
> Currently I'm writing messages to a file with:
>
> BOOST_LOG(mylogger) << __FUNCSIG__ << " message text";
>
> I'd prefer if the function signature (let's assume for now that the
> macro is supported by all compilers) is written automatically without me
> having to add __FUNCSIG__ everywhere. From what I understand I can't
> simply add an attribute to the logger as __FUNCSIG__ would then be used
> in another function (and thus a different function signature would be
> written).

Maybe this is what you seek:

http://tinyurl.com/67ttlq

All you have to do is to add a global named scope attribute and the
appropriate formatter:

http://tinyurl.com/5dvsub

Then you can add BOOST_LOG_FUNCTION and BOOST_LOG_NAMED_SCOPE macros to
markup the scopes and you will have the scope stack in the log with each
log record you make from within these scopes.

> Looking around in the documentation I found BOOST_LOG_WITH_PARAMS (see
> http://boost-log.sourceforge.net/libs/log/doc/html/BOOST_LOG_WITH_PARAMS.html).
> It makes me think that I could define my own BOOST_LOG macro somehow
> like this:
>
> #define BOOST_LOG_FUNCSIG(logger)\
> BOOST_LOG_WITH_PARAMS((logger),
> (::boost::log::sources::keywords::funcsignature = (__FUNCSIG__)))
>
> I see that the macro BOOST_LOG_SEV is defined similarly in
> severity_logger.hpp. However I also see that some more code has to be
> added to the logger to make the logger understand what to do with the
> keyword. For example in the severity logger in open_record() the
> appropriate attribute is set if the severity keyword is found. That
> means I would need to create a new logger and check for my new
> funcsignature attribute in open_record() if I want the function
> signature to be written automatically?

These keywords are one of the ways for the library extension. If you
define your own keyword, you will have to define your logger that will
understand it. Other loggers will just ignore it.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk