Skip to content

Commit

Permalink
make ngnix log stackdriver compatible json (Netflix#74)
Browse files Browse the repository at this point in the history
* make ngnix log stackdriver compatible json
* add severity, log name and more

Co-authored-by: Mattias Springare <mspringare@spotify.com>
  • Loading branch information
2 people authored and GitHub Enterprise committed Feb 10, 2021
1 parent 415e664 commit c671a3b
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions nginx.conf
Expand Up @@ -2,9 +2,38 @@ add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

map $time_iso8601 $time_iso8601_p1 {
~([^+]+) $1;
}

map $msec $millisec {
~\.([0-9]+)$ $1;
}

log_format json_combined
'{'
'"timestamp":"$time_iso8601_p1.${millisec}000",'
'"severity":"INFO",'
'"log":"ngnix",'
'"httpRequest":{'
'"requestMethod":"$request_method",'
'"requestUrl":"$scheme://$host$request_uri",'
'"requestSize":$request_length,'
'"status":$status,'
'"responseSize":$bytes_sent,'
'"userAgent":"$http_user_agent",'
'"remote_addr":"$remote_addr",'
'"remoteIp":"$http_x_forwarded_for",'
'"serverIp":"$server_addr",'
'"referer":"$http_referer",'
'"latency":"${request_time}s",'
'"protocol":"$server_protocol"'
'}'
'}';

server {
listen 80;
access_log /dev/stdout;
access_log /dev/stdout json_combined;
error_log /dev/stderr;

location /api {
Expand All @@ -23,4 +52,4 @@ server {
index index.html;
}

}
}

0 comments on commit c671a3b

Please sign in to comment.