Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to solve this problem by extending <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/AccessLogValve.html" rel="nofollow"><code>AccessLogValve</code></a> and overriding <a href="http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/AccessLogValve.html#log%28java.lang.String%29" rel="nofollow"><code>public log(java.lang.String message)</code></a>:</p> <pre><code>public class SanitizedAccessLogValve extends AccessLogValve { private static Pattern pattern = Pattern.compile("\\b(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})\\b"); /* This method will sanitize any cc numbers in the string and replace them with x's */ private String sanitize(String string) { String sanitizedString = string; if(string != null) { StringBuffer buffer = new StringBuffer(); Matcher matcher = pattern.matcher(string); while(matcher.find()) { MatchResult matchResult = matcher.toMatchResult(); int start = matchResult.start(); int end = matchResult.end(); String matchedText = string.substring(start, end); matcher.appendReplacement(buffer, "xxxxxxxxxxxxxxxx"); } matcher.appendTail(buffer); sanitizedString = buffer.toString(); } return sanitizedString; } @Override public void log(String message) { super.log(sanitize(message)); } } </code></pre> <p>You need to compile this into a jar, and then put that jar file in <code>$CATALINA_HOME/lib</code>.</p> <p>Then in your <code>server.xml</code>:</p> <pre><code>&lt;Valve className="my.valves.SanitizedAccessLogValve" directory="access_logs" prefix="localhost." suffix=".log" pattern='%v %h %t "%r" %s %B %T "%{User-Agent}i"'/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload