From: g0dil Date: Thu, 28 Feb 2008 12:46:58 +0000 (+0000) Subject: Utils/Logger: Fix SENF_LOG_CONF to support top-level areas and streams X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=2400f5c9d91e715773ed965fb92da1b6a54903e5;p=senf.git Utils/Logger: Fix SENF_LOG_CONF to support top-level areas and streams Utils/Logger: Add some internal implementation documentation concerning SENF_LOG_CLASS_AREA() git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@716 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Utils/Logger/AreaRegistry.test.cc b/Utils/Logger/AreaRegistry.test.cc index ee638cf..59086c6 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 eac17e6..ec23c7f 100644 --- a/Utils/Logger/Config.hh +++ b/Utils/Logger/Config.hh @@ -152,7 +152,7 @@ namespace log { stream ::= \e scope_seq \n optional_area::= (_) | \e scope_seq \n level ::= \c VERBOSE | \c NOTICE | \c MESSAGE | \c IMPORTANT | \c CRITICAL | \c DISABLED \n - scope_seq ::= \e scope \e scope \e scope* \n + scope_seq ::= \e scope \e scope* \n scope ::= ( \e name ) \n name ::= arbitrary C++ identifier diff --git a/Utils/Logger/Config.ih b/Utils/Logger/Config.ih index 6c6d5ac..1ead3fc 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 struct Config { - typedef typename Config::compileLimit compileLimit; + typedef typename Config::compileLimit compileLimit; }; # ifndef DOXYGEN template - struct Config + struct Config { 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 a2017b3..db8013f 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 \ { \ @@ -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 \ diff --git a/Utils/Logger/Definitions.ih b/Utils/Logger/Definitions.ih index b5d8369..a40ec3f 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 \ { \ diff --git a/Utils/Logger/main.test.hh b/Utils/Logger/main.test.hh index be89c33..1d20923 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 5e3e2c7..dc47055 100644 --- a/senf.dict +++ b/senf.dict @@ -124,6 +124,7 @@ ForwardingRoute fraunhofer FroblizerArea GlobalScope +GlobalTestArea gre GREPacket GREPacketParser