I\'m trying to save log messages to a central database. In order to do this, I configured the following Appender in log4j\'s xml configuration:
i solved the thing in the following way :
Copied the source code of the JDBCAppender called ACMEJDBCAppender
override the getLogStatement(LoggingEvent event) method, cloning the old event and providing the new one with the escaped message.
Not the cleanest solution from the oop point of view but it does the work. Hope it helps.
protected String getLogStatement(LoggingEvent event) {
LoggingEvent clone = new LoggingEvent(
event.fqnOfCategoryClass,
LogManager.getLogger(event.getLoggerName()),
event.getLevel(),
AidaUtils.sqlEscape(event.getMessage().toString()),
event.getThrowableInformation()!=null ? event.getThrowableInformation().getThrowable() : null
);
return getLayout().format(clone);
}