Logfmt
Logfmt is a key/value-style log encoding format which produces messages that are both human-readable and machine-readable at the same time.
A message which is encoded as logfmt may look like this:
at=info method=GET path=/ host=mutelight.org fwd="124.133.52.161"
dyno=web.2 connect=4ms service=8ms status=200 bytes=1653
Or this:
server_name="example.com" request_id=294df52afa05eb7d3843beaa9c430d85
time_local="06/Jan/2021:10:43:21 +0100" status_code=302
request_method=GET request_scheme=https request_host="example.com"
request_uri="/" remote_addr="159.203.86.51" request_time=0.003
request_length=76 bytes_sent=287 request="GET / HTTP/2.0" remote_user="-"
user_agent="Mozilla/5.0 (compatible; NetcraftSurveyAgent/1.0)"
referer="-" upstream_connect_time=0.000 upstream_addr="127.0.0.1:3000"
upstream_response_time=0.000 upstream_response_length=29
upstream_bytes_received=372 connection_requests=1 worker_pid=19817
I prefer logfmt over other encoding schemes for log messages because these entries remain easy to read for humans without any postprocessing, but retain their full structure.
This means they can still be ingested into log processing and aggregation systems with the same ease as JSON logs, but don’t suffer the drawback of requiring raw logs to be processed by a tool which formats the entries for human viewing before they may be used.
Logfmt originates from Heroku where it was first used in their router.