I am using boost_logging (version 2), and I would like to avoid littering these throughout my code:
BOOST_LOG_NAMED_SCOPE("SomeModuleName")
BOOST_LOG_FUNCTION()
My thinking this second is that I'd prefer to combine them in a macro like this:
#define LOG_NAMED_SCOPE_FUNCTION(name)\
BOOST_LOG_NAMED_SCOPE(name)\
BOOST_LOG_FUNCTION()
But I get an error when I try to do that. See below.
I would be extra happy with a solution that allows me to do something like BOOST_LOG_NAMED_SCOPE("SomeModuleName")
at the module level (which also errors out). Even better would be a solution that does some sort of RAII/AOP to allow me to also append "enter" and "exit" trace messages at the beginning and end of the function, as that's my ultimate goal here.
I am guessing because the unique identifier that gets generated is expanded at the point of macro definition, instead of at macro invocation. I also looked at the DEFERRED and EXPAND helpers, but I'm not sure they're going to help me here.
Here's the error message:
Project/SomeModuleName.cpp:9:5: error: redefinition of '_boost_log_named_scope_sentry_9'
LOG_NAMED_SCOPE_FUNCTION("SomeModuleName")
^
Project/Logging.hpp:24:5: note: expanded from macro 'LOG_NAMED_SCOPE_FUNCTION'
BOOST_LOG_FUNCTION()
^
/usr/local/include/boost/log/attributes/named_scope.hpp:458:36: note: expanded from macro 'BOOST_LOG_FUNCTION'
BOOST_LOG_NAMED_SCOPE_INTERNAL(BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_named_scope_sentry_), BOOST_CURRENT_FUNCTION, __FILE__, __LINE__, ::boost::log::attributes::named_scope_entry::function)
^
/usr/local/include/boost/log/utility/unique_identifier_name.hpp:48:5: note: expanded from macro 'BOOST_LOG_UNIQUE_IDENTIFIER_NAME'
BOOST_LOG_UNIQUE_IDENTIFIER_NAME_INTERNAL(prefix, __LINE__)
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/usr/local/include/boost/preprocessor/cat.hpp:22:32: note: expanded from macro 'BOOST_PP_CAT'
# define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
^
/usr/local/include/boost/preprocessor/cat.hpp:29:34: note: expanded from macro 'BOOST_PP_CAT_I'
# define BOOST_PP_CAT_I(a, b) a ## b
^
<scratch space>:89:1: note: expanded from here
_boost_log_named_scope_sentry_9
^
Project/SomeModuleName.cpp:9:5: note: previous definition is here
Project/Logging.hpp:23:5: note: expanded from macro 'LOG_NAMED_SCOPE_FUNCTION'
BOOST_LOG_NAMED_SCOPE(name)\
^
/usr/local/include/boost/log/attributes/named_scope.hpp:449:36: note: expanded from macro 'BOOST_LOG_NAMED_SCOPE'
BOOST_LOG_NAMED_SCOPE_INTERNAL(BOOST_LOG_UNIQUE_IDENTIFIER_NAME(_boost_log_named_scope_sentry_), name, __FILE__, __LINE__, ::boost::log::attributes::named_scope_entry::general)
^
/usr/local/include/boost/log/utility/unique_identifier_name.hpp:48:5: note: expanded from macro 'BOOST_LOG_UNIQUE_IDENTIFIER_NAME'
BOOST_LOG_UNIQUE_IDENTIFIER_NAME_INTERNAL(prefix, __LINE__)
^
note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all)
/usr/local/include/boost/preprocessor/cat.hpp:22:32: note: expanded from macro 'BOOST_PP_CAT'
# define BOOST_PP_CAT(a, b) BOOST_PP_CAT_I(a, b)
^
/usr/local/include/boost/preprocessor/cat.hpp:29:34: note: expanded from macro 'BOOST_PP_CAT_I'
# define BOOST_PP_CAT_I(a, b) a ## b
^
<scratch space>:85:1: note: expanded from here
_boost_log_named_scope_sentry_9
^