Skip to content

Instantly share code, notes, and snippets.

@bgv
Last active June 11, 2016 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgv/dc349b038ce04093e3a0732af72c799b to your computer and use it in GitHub Desktop.
Save bgv/dc349b038ce04093e3a0732af72c799b to your computer and use it in GitHub Desktop.
Apache configuration to forward structured JSON formatted log to syslog facility
# Create a log format called 'log_json' that emits, in json, the parts of an http
# request I care about. For more details on the features of the 'LogFormat'
# directive, see the apache docs:
# http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
LogFormat "{ \"@timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \"@message\": \"%m %H %U%q %s\", \"@fields\": { \"client\": \"%a\", \"duration_usec\": %D, \"status\": %s, \"request\": \"%U%q\", \"method\": \"%m\", \"protocol\": \"%H\", \"referrer\": \"%{Referer}i\", \"user-agent\": \"%{User-agent}i\" } }" log_json
# Apache 2.4 add sub-second precision logging
# http://httpd.apache.org/docs/2.4/mod/mod_log_config.html#formats
LogFormat "{ \"@timestamp\": \"%{%Y-%m-%dT%H:%M:%S}t.%{msec_frac}t%{%z}t\", \"@message\": \"%m %H %U%q %s\", \"@fields\": { \"client\": \"%a\", \"duration_usec\": %D, \"status\": %s, \"request\": \"%U%q\", \"method\": \"%m\", \"protocol\": \"%H\", \"referrer\": \"%{Referer}i\", \"user-agent\": \"%{User-agent}i\" } }" log_json
# Pipe log to default rsyslog
CustomLog "|/usr/bin/logger -t httpd -p local0.info" log_json
# Pipe log to custom syslog server on localhost UDP port 5000
CustomLog "|/usr/bin/logger -t httpd -p local0.info --server 127.0.0.1 --port 5000 -d" log_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment