iximiuz / client-go-examples

Collection of mini-programs demonstrating Kubernetes client-go usage.
https://labs.iximiuz.com/playgrounds/k8s-client-go/
Apache License 2.0
1.02k stars 131 forks source link

Using klog in the examples #3

Closed mauriciopoppe closed 2 years ago

mauriciopoppe commented 2 years ago

Thank you for the blogposts and for these snippets! I think it's very useful to see the timestamps in the examples that you have, I was wondering if you'd be ok if I submit a change replacing fmt.Printf with klog.Infof

iximiuz commented 2 years ago

Hi Mauricio! I think it will be a great improvement for the mini-programs indeed!

Have you considered using go-logr/logr for that? It's a flexible logging interface that can be backed by many concrete logger implementations, including klog.

mauriciopoppe commented 2 years ago

Thanks for the suggestion, I tried using klogr and while it might be great for a full fledged application I think the output makes it a little bit confusing if you're not aware of what it does, for example the output for crud-dynamic-example becomes:

go run main.go
I0407 21:35:54.874965 3335273 main.go:61]  "msg"="Created ConfigMap"  "name"="crud-dynamic-simple-2xz78" "namespace"="default"
I0407 21:35:54.919574 3335273 main.go:81]  "msg"="Read ConfigMap"  "name"="crud-dynamic-simple-2xz78" "namespace"="default"
I0407 21:35:54.969407 3335273 main.go:102]  "msg"="Updated ConfigMap"  "name"="crud-dynamic-simple-2xz78" "namespace"="default"
I0407 21:35:55.016497 3335273 main.go:121]  "msg"="Deleted ConfigMap"  "name"="crud-dynamic-simple-2xz78" "namespace"="default"

I was thinking that these examples are short enough to use std libraries and using things like klog might be an overkill, I think I'm going to use klog in some of the examples that you have but in my fork.

iximiuz commented 2 years ago

On second thought, keeping the mini-programs dependencies at the bare minimum probably might be even more important than rich logging. Thanks for opening this issue anyway, it was good food for thought!