Skip to content

Instantly share code, notes, and snippets.

@eqyiel
Forked from vmadman/apache-json-log-format
Created May 4, 2020 03:26
Show Gist options
  • Save eqyiel/d40f45baddbb5a3b35b6d06b5aee7669 to your computer and use it in GitHub Desktop.
Save eqyiel/d40f45baddbb5a3b35b6d06b5aee7669 to your computer and use it in GitHub Desktop.
An apache log format that allow access logs (but not error logs) to be output in JSON format. I found this here: http://untergeek.com/2012/10/11/getting-apache-to-output-json-for-logstash/ -- but modified it for my purposes a good bit.
# Access Logs
LogFormat "{ \
\"@vips\":[\"%v\"], \
\"@source\":\"%v%U%q\", \
\"@source_host\": \"%v\", \
\"@source_path\": \"%f\", \
\"@tags\":[\"Apache\",\"Access\"], \
\"@message\": \"%h %l %u %t \\\"%r\\\" %>s %b\", \
\"@fields\": { \
\"timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
\"clientip\": \"%a\", \
\"duration\": %D, \
\"status\": %>s, \
\"request\": \"%U%q\", \
\"urlpath\": \"%U\", \
\"urlquery\": \"%q\", \
\"method\": \"%m\", \
\"referer\": \"%{Referer}i\", \
\"user-agent\": \"%{User-agent}i\", \
\"bytes\": %B \
} \
}" ls_apache_json
# The catch-all
CustomLog "||/usr/local/bin/udpclient.pl 127.0.0.1 5001" ls_apache_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment