Skip to content

Instantly share code, notes, and snippets.

@namedgraph
Last active December 17, 2015 18:49
Show Gist options
  • Save namedgraph/5656373 to your computer and use it in GitHub Desktop.
Save namedgraph/5656373 to your computer and use it in GitHub Desktop.
Tomcat AccessLogValve pattern producing HTTP access logs in RDF Turtle format using HTTP Vocabulary. Configured in server.xml.
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Service name="Catalina">
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".ttl"
pattern="[ a &lt;http://www.w3.org/2011/http#Connection&gt; ; &lt;http://semantic-web.dk/ontologies/http#remoteAuthority&gt; &quot;%a&quot; ; &lt;http://www.w3.org/2011/http#connectionAuthority&gt; &quot;%v:%p&quot; ; &lt;http://www.w3.org/2011/http#requests&gt; ([ a &lt;http://www.w3.org/2011/http#Request&gt; ; &lt;http://purl.org/dc/terms/date&gt; &quot;%{yyyy-MM-dd}tT%{HH:mm:ss}t&quot;^^&lt;http://www.w3.org/2001/XMLSchema#dateTime&gt; ; &lt;http://www.w3.org/2011/http#methodName&gt; &quot;%m&quot; ; &lt;http://www.w3.org/2011/http#mthd&gt; &lt;http://www.w3.org/2011/http-methods#%m&gt; ; &lt;http://www.w3.org/2011/http#absolutePath&gt; &quot;%U&quot; ; &lt;http://www.w3.org/2011/http#absoluteURI&gt; &quot;http://%v:%p%U%q&quot; ; &lt;http://www.w3.org/2011/http#headers&gt; ([ a &lt;http://www.w3.org/2011/http#RequestHeader&gt; ; &lt;http://www.w3.org/2011/http#fieldName&gt; &quot;Referer&quot; ; &lt;http://www.w3.org/2011/http#fieldValue&gt; &quot;%{Referer}i&quot; ; &lt;http://www.w3.org/2011/http#hdrName&gt; &lt;http://www.w3.org/2011/http-headers#referer&gt; ] [ a &lt;http://www.w3.org/2011/http#RequestHeader&gt; ; &lt;http://www.w3.org/2011/http#fieldName&gt; &quot;User-Agent&quot; ; &lt;http://www.w3.org/2011/http#fieldValue&gt; &quot;%{User-Agent}i&quot; ; &lt;http://www.w3.org/2011/http#hdrName&gt; &lt;http://www.w3.org/2011/http-headers#user-agent&gt; ]) ; &lt;http://www.w3.org/2011/http#resp&gt; [ a &lt;http://www.w3.org/2011/http#Response&gt; ; &lt;http://www.w3.org/2011/http#statusCodeNumber&gt; &quot;%s&quot;^^&lt;http://www.w3.org/2001/XMLSchema#int&gt; ] ]) ] ." />
</Host>
</Engine>
</Service>
</Server>
@namedgraph
Copy link
Author

If your Tomcat is behind a proxy (such as Varnish cache), try %{X-Forwarded-For}i instead of %a to get the original remote address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment