Skip to content

Instantly share code, notes, and snippets.

@tomprogers
Created August 21, 2022 18:58
Show Gist options
  • Save tomprogers/bc90e944134c21f34d5d7402bf8ffcf0 to your computer and use it in GitHub Desktop.
Save tomprogers/bc90e944134c21f34d5d7402bf8ffcf0 to your computer and use it in GitHub Desktop.
Logging guidelines

Log levels

Severity Method Appropriate for
MAX mark() a) Temporary only, while developing; never on master or in production
5 fatal() a) Every uncaught exception
4 error() a) Every throw, swallowed or not
3 warn() a) Any debug or info that contains bad news
2 info() a) Side effects after success; b) task progress; see warn
1 trace() a) Upon entry into every routine, sig & values
MIN debug() a) Every calculation of note; b) "attempting X..."; see warn

Logging guidelines

  • Log statements must be present in the application before the bad things happens that you wish to study. You can't retroactively create logging data by adding log statements after the fact.
  • Do not bother with English style-guide stuff: sentence case, grammar, etc. Make it accurate, precise, brief, and clear, and be done.
  • Never add noisy nonsense (e.g. !!!!!, >>>> HERE <<<<, etc.) to a log statement for the purpose of making it stand out.
  • When dumping a variable, do it in a way that will reveal its real datatype as well as its value. In JS, that means using JSON.stringify.
  • It is better (because clearer) to log that you are about to try a risky operation than to log that you have just completed the risky operation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment