Logging best practices

The first item on our best practice checklist is leveled logging. When using leveled logging, there are two aspects you need to consider:

  • Selecting the appropriate log level to use for each message: The majority of logging packages for Go applications support at least the DEBUG, INFO, and ERROR levels. However, your preferred logging solution might also support more granular log levels, such as TRACE, DEBUGand WARNING.
  • Deciding which log levels to actually output: For instance, perhaps you want your application to only output messages at the INFO and ERROR levels to reduce the volume of produced logs.

When debugging an application, it makes sense to also include DEBUG or TRACE messages in the logs so that you can ...

Get Hands-On Software Engineering with Golang now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.