I think you'd so something like:
template <class T> class Example { Example() {} void doSomething() { LOG4CXX_DEBUG(getLogger(), "Hello, World"); }
private: log4cxx::LoggerRef& getLogger() { static log4cxx::LoggerRef logger(log4cxx::Logger::getLogger( LOG4CXX_LOCATION.getClassName())); return logger; } };
The code fragment depends on the LocationInfo class introduced after 0.9.7 to get the class name. The class name may be returned as "" for early Microsoft compilers ( _MSC_VER < 1300). Please feel free to enhance include/log4cxx/spi/location/locationinfo.h if your compiler can return class location but the macros don't handle it.
On Jan 30, 2005, at 10:51 AM, Daniel Einspanjer wrote:
Does no one else have a problem with needing to log messages from templated classes? If anyone else has solved this problem, I would very much like to hear your solution.
Thanks, Daniel
On Thu, 20 Jan 2005 15:51:41 -0500, Daniel Einspanjer <[EMAIL PROTECTED]> wrote:Could anyone share their methods for logging within a templated class?
Specifically, the problem I don't have a good solution for is the static instantiation of a logger object at all, let alone one that has a name giving the particular class for which the template is being used.