Skip to content

Instantly share code, notes, and snippets.

@byrnedo
Last active May 20, 2020 13:39
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 byrnedo/501cf41e1139e30cbbee88126d960957 to your computer and use it in GitHub Desktop.
Save byrnedo/501cf41e1139e30cbbee88126d960957 to your computer and use it in GitHub Desktop.
Json Nginx Logging
map $msec $millis { ~(.*)\.(.*) $2; }
map $time_iso8601 $time_iso8601_m { ~(.*)\+(.*) $1.$millis+$2; }
log_format json_combined escape=json
'{'
'"_ms": "$millis",' # Has to be here in order for timestamp to work. Wat
'"timestamp": "$time_iso8601_m",'
'"service": "sp-frontend",'
'"remote_addr":"$remote_addr",'
'"message":"[$status] $request_method $request_uri",'
'"method": "$request_method",'
'"status": $status,'
'"sent_length":$body_bytes_sent,'
'"duration_s":$request_time,'
'"referrer":"$http_referer",'
'"user_agent":"$http_user_agent",'
'"level": "info",'
'"proto": "$server_protocol",'
'"url": "$request_uri"'
'}';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment