Re: [Log4cplus-devel] Custom Appenders using Properties?
Logging Framework for C++
Brought to you by:
wilx
From: Václav H. <v.h...@sh...> - 2011-04-07 05:34:31
|
Nate Reid wrote, On 7.4.2011 2:27: > I've subclassed FileAppender with my own custom class and I would like to > use the log4cplus properties system to configure the logging to use the > custom class. The problem is that it appears that the custom class needs to > be registered with the AppenderFactory. However, it looks like the > registration, although done at runtime with the call to > initializeFactoryRegistry() from src/factory.cxx does the trick, it only > registers the Appenders/etc that it's aware of. It also looks like the > FactoryTemp and support classes are an implementation detail of factory.cxx > and do not appear to be accessible externally. E.g. they are not defined in > the factory header file. > Is there a way to register custom Appenders/etc so that they can be used > within a Property configuration? > I'd like to have something like this: > > // log.properties > > log4cplus.rootLogger=DEBUG, Custom > log4cplus.appenders.Custom=CustomNS::MyAppender > ... > > Thanks! > -Nate > > P.S. sorry for cross-posting this to the wilx list as well. You can have that. Just get the appenders registry using log4cplus::spi::getAppenderFactoryRegistry() and register your own custom appender factory class inherited from log4cplus::spi::AppenderFactory with all the appropriate member functions overriden. Something like this should do it: class MyAppenderFactory : public log4cplus::spi::AppenderFactory { virtual log4cplus::tstring getTypeName() {...} virtual SharedAppenderPtr createObject(const log4cplus::helpers::Properties& props) {...} }; log4cplus::getAppenderFactoryRegistry().put(std::auto_ptr<log4cplus::spi::AppenderFactory>(new MyAppenderFactory)); -- wilx |