You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.2 KiB
1.2 KiB
Table Of Contents
Logging
- Avoid print formatting messages on loggers, prefer to use fields on the logger to encapsulate additional information
// Avoid This Style, it bakes too much information into an unformatted message log.Debugf("something special %s happened", somethingSpecial) // Prefer this style with fields log.WithFields(log.Fields{ "somethingSpecial": somethingSpecial }).Debug("something special happened")
- Pass loggers through the function chain as they become more specialized. This keeps extra fields on the loggers from
higher contexts and preserves additional information captured during the process of getting to where the current
line is being logged. The logger should be one of the first arguments defined for helper functions. Public functions
should not require a logger to be passed, but may offer a similar method with a logger input.
func doSomething(logger *log.Entry, ...) { //does something logger.Debug("Something") specialLogger = logger.WithFields(log.Fields{ "specialField", value }) doSubSomething(specialLogger, ...) } func doSubSomething(logger *log.Entry, ...) {}