Skip to content

Instantly share code, notes, and snippets.

@mustmodify
Last active September 26, 2019 15:42
Show Gist options
  • Save mustmodify/0341d2752d26ed462ec7e57efe4bd547 to your computer and use it in GitHub Desktop.
Save mustmodify/0341d2752d26ed462ec7e57efe4bd547 to your computer and use it in GitHub Desktop.

Logging should look like this. Each entry should be on one line... I formatted it for readability. The schema is designed to have standard elements but also be flexible enough for any situation.

Each entry is valid JSON. A file of all of these lines would, obviously, not be valid JSON because you would need commas and [ ].

Each entry MUST have the following key:

  • event
  • app
  • version - the first n characters of the git commit hash of the deployed code. If development or whatever, UNK for unknown is acceptable.
  • env - one of "production", "development", "edge", "demo", etc.
  • timestamp - I'm open to unix timestamps instead of the format below.

Each entry SHOULD have the following keys. Seek approval if not.

  • message

Each entry may have the following keys:

  • details (value must be a hash.)
    • keys should be fairly standard based on the event key.
    • Different events will have different details.
    • 'user' is highly preferred if present.
  • scope - sometimes needed to provide just a bit more context wrt 'event' but doesn't have the overhead of parsing 'details'.
{
  "event": "http", 
  "message": "[200] patients#index", 
  "app": "reporting", "version": "UNK", "env": "development", 
  "timestamp": "2019-09-16T14:48:49.079Z",
  "env": "staging",
  "details": 
  {
    "user": "[email protected] <Johnathon Wright>", "role": "admin",
    "method": "GET", "path": "/", "format": "html", "controller": "patients", "action": "index", "status": "200", 
    "duration". 125.22, "host": "dev.physioagereporting.com", "params": {}, 
    }
}
{"event":"auth","message":"Authenticating","details":{"user":"[email protected]","medium":"params"}}

Anonymous user:

{"event":"http","message":"[302] patients#index","app":"reporting","version":"UNK","env":"development","timestamp":"2019-09-16T14:48:31.458Z", "details":{"method":"GET","path":"/","format":"html","controller":"patients","action":"index","status":302,"duration":132.22,"view":0.0,"db":0.0,"location":"http://dev.physioagereporting.com/user_sessions/new","host":"dev.physioagereporting.com","params":{},"user":"Anonymous","role":"guest",}}

From another environment:

{"event":"http","message":"[200] recommendations#index","app":"reporting","version":"5446b9db","env":"production","timestamp":"2019-09-26T14:32:44.553Z","details":{"method":"GET","path":"/visits/9870/recommendations.json","format":"json","controller":"recommendations","action":"index","status":200,"duration":18.27,"view":1.51,"db":3.55,"host":"www.physioagereporting.com","params":{"visit_id":"9870"},"user":"[email protected] <Some Hu>","role":"patient"}}

Some parameters should be filtered:

{"event":"http","message":"[302] user_sessions#create","app":"reporting","version":"UNK","env":"development","timestamp":"2019-09-05T20:03:51.128Z","details":{"method":"POST","path":"/user_sessions","format":"html","controller":"user_sessions","action":"create","status":302,"duration":95.18,"view":0.0,"db":9.16,"location":"http://dev.physioagereporting.com/patients/new","host":"dev.physioagereporting.com","params":{"user_session":{"username":"[email protected]","password":"[FILTERED]"},"button":""},"user":"[email protected] <Johnathon Wright>","role":"admin"}}

Some events are for metrics, which uses 'scope':

{"event":"time","scope":"physioage.grades.classify","message":15.161704825,"app":"reporting","env":"production","version":"5446b9db","timestamp":"2019-09-05T20:03:51.128Z"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment