diff --git a/Utils/Logger/AreaRegistry.test.cc b/Utils/Logger/AreaRegistry.test.cc index ee638cfe31ed8c62f228d20c2aee786b76e5a3a4..59086c61f68ef7e4c8c87b73dd4c4567c335bd9e 100644 --- a/Utils/Logger/AreaRegistry.test.cc +++ b/Utils/Logger/AreaRegistry.test.cc @@ -37,7 +37,8 @@ BOOST_AUTO_UNIT_TEST(areaRegistry) { - char const * areas[] = { "senf::log::DefaultArea", + char const * areas[] = { "GlobalTestArea", + "senf::log::DefaultArea", "senf::log::test::Foo", "senf::log::test::myArea" }; diff --git a/Utils/Logger/Config.hh b/Utils/Logger/Config.hh index eac17e6a63c57345ded0586cafa6c2d5b3ae33a7..ec23c7f688c3070ac424c62ad840a74682f93551 100644 --- a/Utils/Logger/Config.hh +++ b/Utils/Logger/Config.hh @@ -152,7 +152,7 @@ namespace log { <tr><td>stream</td> <td>::= \e scope_seq \n</td></tr> <tr><td>optional_area</td><td>::= <tt>(_)</tt> | \e scope_seq \n</td></tr> <tr><td>level</td> <td>::= \c VERBOSE | \c NOTICE | \c MESSAGE | \c IMPORTANT | \c CRITICAL | \c DISABLED \n</td></tr> - <tr><td>scope_seq</td> <td>::= \e scope \e scope \e scope* \n</td></tr> + <tr><td>scope_seq</td> <td>::= \e scope \e scope* \n</td></tr> <tr><td>scope</td> <td>::= <tt>(</tt> \e name <tt>)</tt> \n</td></tr> <tr><td>name</td> <td>::= arbitrary C++ identifier</td></tr> </table> diff --git a/Utils/Logger/Config.ih b/Utils/Logger/Config.ih index 6c6d5ac7f4a588881bcfb5d4036846d2d76f3dbe..1ead3fcb3153940283fce44e30bad28bd5c25e27 100644 --- a/Utils/Logger/Config.ih +++ b/Utils/Logger/Config.ih @@ -41,17 +41,19 @@ namespace senf { namespace log { namespace detail { + struct na {}; + /// Internal: Compile time configuration for given \a Stream and \a Area template <class Stream, class Area> struct Config { - typedef typename Config<Stream,void>::compileLimit compileLimit; + typedef typename Config<Stream,na>::compileLimit compileLimit; }; # ifndef DOXYGEN template <class Stream> - struct Config<Stream, void> + struct Config<Stream, na> { typedef typename Stream::compileLimit compileLimit; }; @@ -68,35 +70,40 @@ namespace detail { #define SENF_LOG_PREDECL_(s, state, elem) \ namespace elem { state } -#define SENF_LOG_PREDECL(seq) \ +#define SENF_LOG_PREDECL_long(seq) \ BOOST_PP_SEQ_FOLD_RIGHT( SENF_LOG_PREDECL_, \ class SENF_PP_SEQ_BACK(seq);, \ BOOST_PP_SEQ_POP_BACK(seq) ) +#define SENF_LOG_PREDECL_short(seq) \ + class SENF_PP_SEQ_BACK(seq); + +#define SENF_LOG_PREDECL(seq) \ + BOOST_PP_CAT(SENF_LOG_PREDECL_, \ + BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(seq)),long,short))(seq) + #define SENF_LOG_NIL(x) #define SENF_LOG_CONF_DEFINE(stream, area, level) \ SENF_LOG_PREDECL(stream) \ - BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(area)), \ - SENF_LOG_PREDECL, \ - SENF_LOG_NIL)(area) \ + SENF_LOG_PREDECL(area) \ namespace senf { namespace log { namespace detail { \ template <> \ struct Config< SENF_LOG_SEQ_TO_NAME(stream), \ - BOOST_PP_IF(BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(area)), \ - SENF_LOG_SEQ_TO_NAME(area), \ - void) > \ + SENF_LOG_SEQ_TO_NAME(area) > \ { typedef senf::log::level compileLimit; }; \ }}} #ifdef SENF_LOG_CONF +# define _ senf::log::detail::na # define SLC_elt(r, data, elt) \ SENF_LOG_CONF_DEFINE elt BOOST_PP_SEQ_FOR_EACH(SLC_elt, none, SENF_LOG_CONF) # undef SLC_elt +# undef _ #endif diff --git a/Utils/Logger/Definitions.hh b/Utils/Logger/Definitions.hh index a2017b31d7f60c575577701a554777d4a2a2cb37..db8013fa7d5c4d5f7ec90990fb322da684189ec5 100644 --- a/Utils/Logger/Definitions.hh +++ b/Utils/Logger/Definitions.hh @@ -56,7 +56,7 @@ namespace log { \hideinitializer */ -# define SENF_LOG_DEFINE_STREAM(stream, defaultLevel_, runtimeLimit_, compileLimit_) \ +# define SENF_LOG_DEFINE_STREAM(stream, defaultLevel_, runtimeLimit_, compileLimit_) \ struct stream \ : public senf::log::detail::StreamBase, public senf::singleton<stream> \ { \ @@ -86,8 +86,9 @@ namespace log { \hideinitializer */ + // See Definitions.ih for implementation details on SENF_LOG_CLASS_AREA # define SENF_LOG_CLASS_AREA() \ - SENF_LOG_DEFINE_AREA_I( \ + SENF_LOG_DEFINE_AREA_I( \ SENFLogArea, \ std::string v_name() const \ { std::string s (fullName()); return std::string(s,0,s.size()-13); }); \ @@ -101,7 +102,7 @@ namespace log { \hideinitializer */ -# define SENF_LOG_DEFINE_ALIAS(alias,args) \ +# define SENF_LOG_DEFINE_ALIAS(alias,args) \ struct alias : public senf::log::detail::AliasBase \ { \ template <class Base> \ diff --git a/Utils/Logger/Definitions.ih b/Utils/Logger/Definitions.ih index b5d8369dc5aab63d49b06e19772f8e1d435e2e4c..a40ec3f01c12121b6f18f9fb88700c4f5f140ab0 100644 --- a/Utils/Logger/Definitions.ih +++ b/Utils/Logger/Definitions.ih @@ -30,7 +30,42 @@ ///////////////////////////////ih.p//////////////////////////////////////// -#define SENF_LOG_DEFINE_AREA_I(area, decls) \ +// Implementation details concerning SENF_LOG_CLASS_AREA +// +// The SENF_LOG_CLASS_AREA statement shall declare the containing class as it's own default area. Of +// course, we cannot make the containing class into an area. Therefor we need to trick around a bit: +// +// We begin by defining an area SENFLogArea with in the class. This area however is hacked, so that +// it's name() member will return the name of the containing class (which is simple: just cut of the +// last couple of characters of the name since the name will always end in '::SENFLogArea'). +// +// This however does not allow the use of the containing class as an area. There are several places +// which need to be adjusted to allow using the containing class as an area: The logging statements +// (SENF_LOG), the compile time configuration via SENF_LOG_CONF and the runtime configuration via +// route statements. +// +// Lets begin with the compile time configuration. The compile time configuration is done using +// specialization of the senf::log::detail::Config template. This doesn't care, what the area +// template argument really is. Therefore, compile-time configuration just uses the containing class +// as is. So we need to make sure, that the logging statements use the containing class when +// checking the compile-time limit whereas they need to use the nested SENFLogArea when calling the +// targets. +// +// So let's look at the logging statements. The central logic for parsing the logging parameters is +// in SENF_LOG_MERGE_PARAMETERS in Parameters.ih. Here we have a special case which detects classes +// with a SENFLogArea member and then set's things up correctly: It uses the containing class for +// compile time checking (this is, what 'area_base' typedef is for) while using the nested +// SENFLogArea for routing (this is, what the 'area' typedef is for). +// +// So the last thing which needs to be adjusted is the routing which is part of the Target +// class. Here for each template taking an area as an argument we really provide TWO templates, one +// taking the area directly, the other checking for a nested SENFLogArea member. We can +// differentiate these overloads using boost::enable_if and friends. +// +// This setup makes a class with SENF_LOG_CLASS_AREA() look like an ordinary area even though the +// implementation is somewhat different. + +#define SENF_LOG_DEFINE_AREA_I(area, decls) \ struct area \ : public senf::log::detail::AreaBase, public senf::singleton<area> \ { \ diff --git a/Utils/Logger/main.test.hh b/Utils/Logger/main.test.hh index be89c3325e9753871657dc75bcb01277cd59ad88..1d209236ffe26f5698d65ed69d72e50c8643b769 100644 --- a/Utils/Logger/main.test.hh +++ b/Utils/Logger/main.test.hh @@ -33,6 +33,7 @@ #endif #define SENF_LOG_CONF (( (senf)(log)(Debug), (_), NOTICE )) \ + (( (senf)(log)(test)(myStream), (GlobalTestArea), IMPORTANT )) \ (( (senf)(log)(test)(myStream), (senf)(log)(test)(Foo), VERBOSE )) #include "Logger.hh" @@ -40,6 +41,8 @@ //#include "main.test.mpp" ///////////////////////////////hh.p//////////////////////////////////////// +SENF_LOG_DEFINE_AREA(GlobalTestArea); + namespace senf { namespace log { namespace test { diff --git a/senf.dict b/senf.dict index 5e3e2c746893abc59188dc306301c48a10e7fa1a..dc47055c567e3c17ea1017e39eb69c08d1ae3b03 100644 --- a/senf.dict +++ b/senf.dict @@ -124,6 +124,7 @@ ForwardingRoute fraunhofer FroblizerArea GlobalScope +GlobalTestArea gre GREPacket GREPacketParser