Skip to content

Instantly share code, notes, and snippets.

@bahamat
Last active September 14, 2016 08:12
Show Gist options
  • Save bahamat/93d740e8f9c22f3b0466 to your computer and use it in GitHub Desktop.
Save bahamat/93d740e8f9c22f3b0466 to your computer and use it in GitHub Desktop.
nginx log_format bunyan
log_format bunyan '{'
'"name": "nginx/$nginx_version",'
'"hostname": "$hostname",'
'"pid": "$pid",'
'"level": 30,'
'"time": "$time_iso8601",'
'"v": 0,'
'"msg": "access",'
'"remoteAddress": "$remote_addr",'
'"remotePort": "$remote_port",'
'"req": {'
'"method": "$request_method",'
'"url": "$request_uri",'
'"headers": {'
'"user-agent": "$http_user_agent",'
'"host": "$host",'
'"referrer": "$http_referrer",'
'"username": "$remote_user",'
'"content-type": "$content_type",'
'"content-length": "$content_length",'
'"accept": "$http_accept",'
'"accept-language": "$http_accept_language",'
'"accept-encoding": "$http_accept_encoding"'
'},'
'"serverProtocol": "$server_protocol",'
'"requestLength": "$request_length"'
'},'
'"res": {'
'"statusCode": "$status",'
'"headers": {'
'"server": "nginx/$nginx_version",'
'"content-length": "$body_bytes_sent"'
'},'
'"responseTime": "$request_time"'
'}'
'}';
@bahamat
Copy link
Author

bahamat commented Mar 17, 2016

Example bunyan output:

[2016-03-17T19:42:41+00:00]  INFO: nginx/1.9.5/59926 on 237662da-0720-4ae2-81b5-3c42946000a4: access (remoteAddress=98.176.120.243, remotePort=28263, req.serverProtocol=HTTP/1.1, req.requestLength=172, res.responseTime=0.000)
    GET / HTTP/1.1
    user-agent: curl/7.43.0
    host: nginx-bunyan.inst.d8dbab84-3db1-ef79-c96e-d87655e95380.us-sw-1.triton.zone
    referrer: http://www.google.com/
    username: -
    content-type: -
    content-length: -
    accept: */*
    accept-language: -
    accept-encoding: -
    --
    HTTP/1.1 200 OK
    server: nginx/1.9.5
    content-length: 3
[2016-03-17T19:42:47+00:00]  INFO: nginx/1.9.5/59926 on 237662da-0720-4ae2-81b5-3c42946000a4: access (remoteAddress=98.176.120.243, remotePort=20738, req.serverProtocol=HTTP/1.1, req.requestLength=417, res.responseTime=0.000)
    GET / HTTP/1.1
    user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko) Version/9.0.3 Safari/601.4.4
    host: nginx-bunyan.inst.d8dbab84-3db1-ef79-c96e-d87655e95380.us-sw-1.triton.zone
    referrer: -
    username: -
    content-type: -
    content-length: -
    accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    accept-language: en-us
    accept-encoding: gzip, deflate
    --
    HTTP/1.1 200 OK
    server: nginx/1.9.5
    content-length: 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment