epimorphics / json-rails-logger

A custom rails logger that outputs JSON instead of raw text
MIT License
1 stars 1 forks source link

Place platform-specific fields inside a nested structure #11

Closed ijdickinson closed 3 years ago

ijdickinson commented 3 years ago

At the moment, we place all logged fields at the top level of the JSON structure:

{
  "level": "INFO",
  "timestamp": "2021-01-26 14:33:15",
  "rails_environment": "development",
  "method": "GET",
  "path": "/feed_approvals",
  "format": "html",
  "controller": "FeedApprovalsController",
  "action": "index",
  "status": 200,
  "duration": 324.0,
  "view": 240.1,
  "exception": null,
  "exception_object": null
}

Following a suggestion from @andrew-pickin-epi, we will nest output keys that Rails-specific under a sub-key:

{
  "level": "INFO",
  "timestamp": "2021-01-26 14:33:15",
  "method": "GET",
  "path": "/feed_approvals",
  "status": 200,
  "duration": 324.0,
  "rails: {
    "action": "index",
    "controller": "FeedApprovalsController",
    "environment": "development",
    "view": 240.1,
    "exception "xxxx",
    "exception_object": "yyyy"
  }
}

Common keys will remain at the top level. Keys with null values will be removed altogether.

andrew-pickin-epi commented 3 years ago

Also have this kind of event. https://kibana-fsa.epimorphics.net/app/kibana#/discover/doc/logstash-*/logstash-default-2021.01.27-000001?id=PmGFRHcBBtbYVXFE3eJn

{"level":"INFO","timestamp":"2021-01-27 15:45:54","rails_environment":"production","message":"server: \"nginx/1.19.1\"\ndate: \"Wed, 27 Jan 2021 15:45:54 GMT\"\ncontent-type: \"application/json\"\ntransfer-encoding: \"chunked\"\nconnection: \"keep-alive\"\nvary: \"Accept-Encoding, Accept, Origin\"\nsleuth-trace-id: \"5988fc18ed2f5bd1\"\nsleuth-span-id: \"5988fc18ed2f5bd1\"\ncache-control: \"max-age=1200\"\nx-cache-status: \"HIT\""}

Which results in

log_message= 
server: "nginx/1.19.1"
date: "Wed, 27 Jan 2021 15:45:54 GMT"
content-type: "application/json"
transfer-encoding: "chunked"
connection: "keep-alive"
vary: "Accept-Encoding, Accept, Origin"
sleuth-trace-id: "5988fc18ed2f5bd1"
sleuth-span-id: "5988fc18ed2f5bd1"
cache-control: "max-age=1200"
x-cache-status: "HIT"
andrew-pickin-epi commented 3 years ago

The kibana log output is about the richest example were have of prior art. It might server as a pattern.

https://kibana-hmlr.epimorphics.net/app/kibana#/discover/doc/c84f80d0-0243-11eb-8589-eb35cb72fe94/fluentd-20210128?id=6j7JSHcBSC-fGwD-TKd8&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:now-1h,to:now))

bogdanadrianmarc commented 3 years ago

Done and should be in release 0.2.0 👌