Menu

#24 add callback appender

open
nobody
Appender (4)
5
2008-04-27
2008-04-27
Anonymous
No

It would be useful to add a new appender that takes a callback function that is executed on a log event. This is useful when writing a library that produces log messages that the client wants to process.

For example:
typedef void (* log_handler_t)( int, const char* );

class CallbackAppender : public log4cxx::AppenderSkeleton
{
public:
CallbackAppender( log_handler_t handler )
: m_handler( handler ) { }

void append ( const log4cxx::spi::LoggingEventPtr &event, log4cxx::helpers::Pool &pool )
{
std::string message;
log4cxx::helpers::Transcoder::encode( event->getMessage(), message );
m_handler( event->getLevel()->getSyslogEquivalent(), message.c_str() );
}

void close() { }
bool requiresLayout() const { return false; }

private:
log_handler_t m_handler;
};

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.