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" };
<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>
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;
};
#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
\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> \
{ \
\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); }); \
\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> \
///////////////////////////////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> \
{ \
#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"
//#include "main.test.mpp"
///////////////////////////////hh.p////////////////////////////////////////
+SENF_LOG_DEFINE_AREA(GlobalTestArea);
+
namespace senf {
namespace log {
namespace test {
fraunhofer
FroblizerArea
GlobalScope
+GlobalTestArea
gre
GREPacket
GREPacketParser