Skip to content

Conversation

@JPadovano1483
Copy link
Contributor

Updated logs to be issued via "slog" instead of "log" package for better consistency across the project

fixes #2364

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))
Copy link
Member

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()

return err
}
log.Printf("Router configuration written to %s", configFile)
slog.Info("Router configuration written to config file", slog.String("configFile", configFile))
Copy link
Member

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.

}
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))
Copy link
Member

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.

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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slog.Error

}
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slog.Error

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slog.Error ?

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slog.Error ?

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))
Copy link
Member

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)
Copy link
Member

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.

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))
Copy link
Member

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.

@JPadovano1483
Copy link
Contributor Author

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.

Copy link
Member

@fgiorgetti fgiorgetti left a 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!

@JPadovano1483 JPadovano1483 merged commit ce10f83 into skupperproject:main Feb 6, 2026
2 checks passed
@JPadovano1483 JPadovano1483 deleted the james-slog-conversion branch February 6, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update all logs to use slog

2 participants