-
Notifications
You must be signed in to change notification settings - Fork 86
updated all logs to use slog #2366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
updated all logs to use slog #2366
Conversation
cmd/network-observer/codegen/main.go
Outdated
| typ = f.X | ||
| default: | ||
| log.Fatalf("unexpected field type: %s %T", field.Names[0], f) | ||
| slog.Error("unexpected field type", slog.Any("field", field.Names[0]), slog.Any("type", f)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To log the type here, I believe you still need fmt.Printf("%T", f) or maybe use reflect.TypeOf(f).String()
internal/kube/adaptor/config_init.go
Outdated
| return err | ||
| } | ||
| log.Printf("Router configuration written to %s", configFile) | ||
| slog.Info("Router configuration written to config file", slog.String("configFile", configFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor/cosmetic suggestion: "Router configuration has been written" as "config file" is printed twice.
internal/kube/certificates/mgr.go
Outdated
| } | ||
| if err := m.checkCertificate(cert.Key(), cert); err != nil { | ||
| log.Printf("Error trying to reconcile %s: %s", cert.Key(), err) | ||
| slog.Error("Error trying to reconcile cert key", slog.String("certKey", cert.Key()), slog.Any("error", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another minor suggestion: "Error trying to reconcile certificate".
Maybe just "key" for the cert.Key() as I see it is being used this way in other parts of the code.
internal/kube/grants/grants.go
Outdated
| func (g *Grants) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
| if r.Method != http.MethodPost { | ||
| log.Printf("Bad method %s for path %s", r.Method, r.URL.Path) | ||
| slog.Info("Bad method for path", slog.String("method", r.Method), slog.String("path", r.URL.Path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Error
internal/kube/grants/tokens.go
Outdated
| } | ||
| if ok := generator.setValidHostsFromSite(site); !ok { | ||
| log.Printf("Could not resolve any target endpoints for site %s in %s", site.Name, site.Namespace) | ||
| slog.Info("Could not resolve any target endpoints for site", slog.String("namespace", site.Namespace), slog.String("name", site.Name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Error
internal/kube/watchers/watchers.go
Outdated
| func (c *EventProcessor) WatchGateways(options dynamicinformer.TweakListOptionsFunc, namespace string, handler DynamicHandler) *DynamicWatcher { | ||
| if !c.HasGateway() { | ||
| log.Println("Cannot watch Gateways; resource not installed") | ||
| slog.Info("Cannot watch Gateways; resource not installed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Error ?
internal/kube/watchers/watchers.go
Outdated
| func (c *EventProcessor) WatchTlsRoutes(options dynamicinformer.TweakListOptionsFunc, namespace string, handler DynamicHandler) *DynamicWatcher { | ||
| if !c.HasTlsRoute() { | ||
| log.Println("Cannot watch TLSRoutes; resource not installed") | ||
| slog.Info("Cannot watch TLSRoutes; resource not installed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slog.Error ?
internal/qdr/amqp_mgmt.go
Outdated
| err := json.Unmarshal([]byte(metadata), &result) | ||
| if err != nil { | ||
| log.Printf("Assuming old format for router metadata %s: %s", metadata, err) | ||
| slog.Error("Assuming old format for router metadata", slog.String("metadata", metadata), slog.Any("error", err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a Warn instead of an Error ?
|
|
||
| func (a *Agent) Create(typename string, name string, entity recordType) error { | ||
| attributes := entity.toRecord() | ||
| log.Println("CREATE", typename, name, attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe CREATE, UPDATE and DELETE could be an action argument with a common message, like: "Management request" or something better.
internal/qdr/qdr.go
Outdated
| log.Printf("TcpConnectors added=%v, deleted=%v", a.TcpConnectors.Added, a.TcpConnectors.Deleted) | ||
| log.Printf("TcpListeners added=%v, deleted=%v", a.TcpListeners.Added, a.TcpListeners.Deleted) | ||
| log.Printf("SslProfiles added=%v, deleted=%v", a.AddedSslProfiles, a.DeletedSSlProfiles) | ||
| slog.Info("TcpConnectors", slog.Any("added", a.TcpConnectors.Added), slog.Any("deleted", a.TcpConnectors.Deleted)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe instead of using just the default logger, the BridgeConfigDifference type could have its own logger, with a component field set.
Probably this suggestion also applies to other entries that are logging from a method.
|
Thanks for the input @fgiorgetti! I made those changes and I added a logger to all the types that are used as receivers and used slog. Let me know if this looks like what you were looking for there. |
fgiorgetti
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Updated logs to be issued via "slog" instead of "log" package for better consistency across the project
fixes #2364