#8314·grpc-go

xds: switch generic xds client to use slog instead of grpclog

Author: purnesh42HCreated May 13, 2025Updated Sep 30, 2026
LabelsP2Type: Internal CleanupArea: xDS

Currently generic xDS and LRS client https://github.com/grpc/grpc-go/tree/master/xds/internal/clients are using grpclog which is not a long term solution as eventually the generic clients need to be moved to a separate repo.

This proposal recommends to use slog.Logger. The logger should be an optional attribute of the lrsclient.Config and xdsclient.Config. If user doesn't provide the logger, a default slog.Logger should be assigned to it

  1. Update xdsclient.Config and lrsclient.Config to add a new Logger field as slog.Logger type

  2. Modify xdsclient.XDSClient and lrsclient.LRSClient internal components: to use the provided Logger implementation from their respective config structs

type XDSClient struct {
    // ... other fields
    logger      slog.Logger
}

type LRSClient struct {
    // ... other fields
    logger      slog.Logger
}
  1. In the init method of xdsclient.go and lrsclient.go, set the default instance of the slog.Logger
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, slog.LevelError)))
  1. When the xDS and LRS clients are instantiated, they may or may not receive the logger through their config structs.

xdsclient.go

func newClient(config *Config, watchExpiryTimeout time.Duration, streamBackoff func(int) time.Duration, target string) (*XDSClient, error) {
    .....
    .....

   if config.logger != nil {
       c.logger = config.logger 
   } else {
      c.logger  = slog.Default()
   }
}

lrsclient.go

func New(config Config) (*LRSClient, error) {
	....
        ....
   if config.logger != nil {
       c.logger = config.logger 
   } else {
      c.logger  = slog.Default()
   }
}
  1. Throughout the client's codebase, existing logging statements (which might currently use grpclog, fmt.Println, or another logging library) would be replaced with calls to the methods of the new logger instance.
if c.logger.Enabled(2) {
     c.logger.Info(mgs, )
}
  1. Internal grpc xds client code should be able to provide an slog.Logger to xdsclient.XDSClient that uses grpc.PrefixLogger underneath. This will require to implement a custom slog.Handler that wraps the grpc.PrefixLogger and use that handler in slog.New() when creating the xdsclient instance.