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:
If you are using SQL server you can use the following
SET QUOTED_IDENTIFIER OFF;
INSERT INTO log_messages ( log_level, message, log_date ) VALUES ( "%p", ":%m", "%d{yyyy-MM-dd HH:mm:ss}" )'
SET QUOTED_IDENTIFIER OFF;
Which shifts the problem to double quotes. If you don't have double quotes in your messages this could solve the problem.
Joao, sorry for being late, but here it is:
<appender name="DB" class="org.apache.log4j.db.DBAppender">
<connectionSource class="org.apache.log4j.db.DriverManagerConnectionSource">
<param name="driverClass" value="org.postgresql.Driver" />
<param name="url" value="jdbc:postgresql://localhost/database" />
<param name="user" value="user" />
<param name="password" value="password" />
</connectionSource>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%t] %c - %m%n" />
</layout>
</appender>
Hope it helps!
I'm not familiar with log4j or JDBC, but I do know JDBC supports prepared statements. Perhaps there is a way to use that with the JDBCAppender