Skip to content

Instantly share code, notes, and snippets.

@wlan0
Created February 25, 2021 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wlan0/f72a4687017e3529d32c976d11cc20b4 to your computer and use it in GitHub Desktop.
Save wlan0/f72a4687017e3529d32c976d11cc20b4 to your computer and use it in GitHub Desktop.
k8s.io/klog/v2
github.com/pkg/errors
InfoS - Structured Info
klog.InfoS("bucket created successfully", "name", obj.Name, key, values string...)
// bucket created successfully name=bucketname
klog.Infof()
ErrorS - Structured Errors
When should you log errors:
- main
if err != nil {
klog.ErrorS(err, "exiting")
}
- fn1
if err != nil {
return errors.Wrap("msg", err)
}
- fn2
open file
if err != nil {
return err
}
Verbosity conventions -
1 - things relevant to major functions in the program. eg "bucket created successfully"
2 - things relevant to minor functions in the program. eg "server listening on port: xyz"
3 - function parameters. eg "create bucket bucketname=xyz provisioner=bac"
4 - metrics about inner working of the code itself eg. "function CreateBucket took 145ms to complete on avg"
5 - logging actual IO - eg. HTTP req and resp, syscalls etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment