I am adding this answer as the links in the highest rated answer look from an older version. I created a custom appender using version 1.2.0 , following what was done in their SysLogAppender. At a high level, you need to do the following:
- Create your own class that inherits their Appender class.
- Implement pure virtual functions
void close() and void append(const spi::InternalLoggingEvent& event) - Register your appender class with AppenderFactoryRegistry.
Here is an example class with code for a class with the namespace yournamespace :: ExampleCustomAppender:
Then the implementation of the methods:
#include <log4cplus/spi/factory.h>
and finally, an example of how it can be used in a configuration file:
log4cplus.rootLogger=INFO, STDOUT, ROLLING, EXAMPLE // other definitions for STDOUT and ROLLING here and then ... log4cplus.appender.EXAMPLE=log4cplus::ExampleCustomAppender log4cplus.appender.EXAMPLE.layout=log4cplus::PatternLayout log4cplus.appender.EXAMPLE.layout.ConversionPattern=%d{%m/%d %H:%M:%S} [%t] %-5p %c{2} - %m%n
I made this code by rendering another code, so it was not compiled as such in this exact format. Notify me of any problems and I will fix it.
source share