title: How to sanitize log messages in Log4j to save them in database
body: <p>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:</p>
  
  <pre><code>&lt;appender name="DB" class="org.apache.log4j.jdbc.JDBCAppender"&gt;
              &lt;param name="URL" value="jdbc:postgresql://localhost/logging_test" /&gt;
              &lt;param name="user" value="test_user" /&gt;
              &lt;param name="password" value="test_password" /&gt;
              &lt;param name="sql" value="INSERT INTO log_messages ( log_level, message, log_date ) VALUES ( '%p', '%m', '%d{yyyy-MM-dd HH:mm:ss}' )" /&gt;
  &lt;/appender&gt;
  </code></pre>
  
  <p>This works fine, except some of the messages contain ', and then the appender fails.</p>
  
  <p>Is there an easy way to do this? </p>