Created
February 25, 2021 19:48
-
-
Save wlan0/f72a4687017e3529d32c976d11cc20b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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