title: Using Apache's CustomLog to regex replace, get unterminated 's' character error
body: <p>I'm trying to sanitise my apache logs of sensitive data as it's passed around in query string parameters. I'm aware this is not good, it cannot be changed.</p>
  
  <p>Following from this question: <a href="https://stackoverflow.com/a/9473943/1046387">https://stackoverflow.com/a/9473943/1046387</a></p>
  
  <p>This is in my <code>apache.conf</code></p>
  
  <pre><code>CustomLog "|/bin/sed -u -E s/'api_key=[^&amp; \t\n]*'/'api_key=\[FILTERED\]'/g &gt;&gt; /var/log/apache2/access.log" combined
  </code></pre>
  
  <p>I've been getting this error:</p>
  
  <pre><code>AH00106: piped log program '/bin/sed -u -E s/'api_key=[^&amp; \\t\\n]*'/'api_key=\\[FILTERED\\]'/g &gt;&gt; /var/log/apache2/access.log' failed unexpectedly
  /bin/sed: -e expression #1, char 14: unterminated `s' command
  </code></pre>
  
  <p>Despite being able to run the command on the box directly:</p>
  
  <pre><code>$ echo "api_key=343" | /bin/sed -u -E s/'api_key=[^&amp; \t\n]*'/'api_key=\[FILTERED\]'/g
  api_key=[FILTERED]
  </code></pre>
  
  <p>Seems like apache isn't handing over the command to <code>sed</code> properly so it's missing some of the arguments. Some problem with escape sequences or something?</p>