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
Update
xdsclient.Configandlrsclient.Configto add a new Logger field asslog.LoggertypeModify
xdsclient.XDSClientandlrsclient.LRSClientinternal 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
}- In the init method of
xdsclient.goandlrsclient.go, set the default instance of theslog.Logger
slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, slog.LevelError)))- When the xDS and LRS clients are instantiated, they may or may not receive the logger through their
configstructs.
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()
}
}- 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, )
}- Internal grpc xds client code should be able to provide an slog.Logger to
xdsclient.XDSClientthat usesgrpc.PrefixLoggerunderneath. This will require to implement a customslog.Handlerthat wraps thegrpc.PrefixLoggerand use that handler inslog.New()when creating the xdsclient instance.
Source: grpc/grpc-go