[log] More questions for Andrey (how to add function signature to messages)

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). 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.htm...). 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? Is there another way to do this more easily? Boris

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.htm...). 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.

On Wed, 20 Aug 2008 18:38:31 +0200, Andrey Semashev <andrey.semashev@gmail.com> wrote:
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:
All you have to do is to add a global named scope attribute and the appropriate formatter:
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.
Great, exactly what I've been looking for! I had skipped named scopes before as I had thought it's something esoteric. :) However when I use BOOST_LOG_FUNCTION() I get a compiler error "'BOOST_LOG_NO_UNUSED_WARNINGS': identifier not found". Do I need to include another header file for BOOST_LOG_NO_UNUSED_WARNINGS to be defined? Boris
[...]

Boris wrote:
On Wed, 20 Aug 2008 18:38:31 +0200, Andrey Semashev <andrey.semashev@gmail.com> wrote:
Boris wrote: However when I use BOOST_LOG_FUNCTION() I get a compiler error "'BOOST_LOG_NO_UNUSED_WARNINGS': identifier not found". Do I need to include another header file for BOOST_LOG_NO_UNUSED_WARNINGS to be defined?
Yes, it seems I missed this: #include <boost/log/utility/no_unused_warnings.hpp> Fixed in CVS.
participants (2)
-
Andrey Semashev
-
Boris