« Back to Index

Apache LogFormat Example

View original Gist on GitHub

Apache LogFormat Example.conf

# Add the following contents to:
# /etc/httpd/conf.d/logging.conf

# Our new log format in structured json style
LogFormat '{"apache":{"timestamp":"%t","status":"%>s","origin_ip":"%{X-Forwarded-For}i","message":"%r","user-agent":"%{User-Agent}i"}}' custom

# Note:
# This is the syntax structure of the LogFormat setting...
# LogFormat <string_formatter> <log_format_name>

# You have to tell Apache which log file to use (app.log) and which formatter to use (custom)
CustomLog "/var/log/component/app.log" custom

# Note:
# This is the syntax structure of the CustomLog setting...
# CustomLog <log_location> <log_format_name>