You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by ANDREW LAZARUS <dr...@me.com> on 2012/11/21 06:36:39 UTC

Not happy with object.h use of namespace in macros

I skipped creating a Jira because this is not exactly a bug in the same sense. The use of namespaces inside macros makes it difficult (if not impossible) for writers of custom Appenders to place their classes inside a namespace, either log4cxx or a namespace of their own. I don’t think that’s the sort of rule to impose on clients. Instead, our macros should fully qualify everything so that they work in any namespace (including global).

I didn’t make all the necessary changes, only the ones required to get my particular custom appender to compile.

diff --git a/src/main/include/log4cxx/helpers/object.h b/src/main/include/log4cxx/helpers/object.h
index 92d44c5..b9386c4 100644
--- a/src/main/include/log4cxx/helpers/object.h
+++ b/src/main/include/log4cxx/helpers/object.h
@@ -61,8 +61,8 @@ static const helpers::Class& getStaticClass();\
 static const log4cxx::helpers::ClassRegistration&  registerClass();
 
 #define IMPLEMENT_LOG4CXX_OBJECT(object)\
-const log4cxx::helpers::Class& object::getClass() const { return getStaticClass(); }\
-const log4cxx::helpers::Class& object::getStaticClass() { \
+const ::log4cxx::helpers::Class& object::getClass() const { return getStaticClass(); }\
+const ::log4cxx::helpers::Class& object::getStaticClass() { \
    static Clazz##object theClass;                         \
    return theClass;                                       \
 }                                                                      \
@@ -71,7 +71,7 @@ const log4cxx::helpers::ClassRegistration& object::registerClass() {   \
     return classReg; \
 }\
 namespace log4cxx { namespace classes { \
-const log4cxx::helpers::ClassRegistration& object##Registration = object::registerClass(); \
+const ::log4cxx::helpers::ClassRegistration& object##Registration = object::registerClass(); \
 } }