From ad23cb1024387c6357a10146c18b5bd9a9f219f9 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 21 Nov 2017 18:05:53 +0000 Subject: [PATCH] Code Style: Prefer WithFields over Infof --- CODE_STYLE.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CODE_STYLE.md b/CODE_STYLE.md index 65d0daf4c..20f97436f 100644 --- a/CODE_STYLE.md +++ b/CODE_STYLE.md @@ -52,6 +52,25 @@ github. These can be added just before merging of the PR to master, and the issue number should be added to the comment, e.g. `// TODO(#324): ...` +## Logging + +We prefer to log with static log messages and include any dynamic information +in fields. + +```golang +logger := util.GetLogger(ctx) + +// Not recommended +logger.Infof("Finished processing keys for %s, number of keys %d", name, numKeys) + +// Recommended +logger.WithFields(logrus.Fields{ + "numberOfKeys": numKeys, + "entityName": name, +}).Info("Finished processing keys") +``` + + ## Visual Studio Code If you use VSCode then the following is an example of a workspace setting that