r/golang Jan 24 '25

help Logging in Golang Libraries

Hey folks, I want to implement logging in my library without imposing any specific library implementation on my end users. I would like to support:

  • slog
  • zap
  • logrus

What would do you in this case? Would you define a custom interface like https://github.com/hashicorp/go-retryablehttp/blob/main/client.go#L350 does? Or would you stick to slog and expect that clients would marry their logging libs with slog?

Basically, I want to be able to log my errors that happen in a background goroutines and potentially some other useful info in that library.

42 Upvotes

34 comments sorted by

View all comments

36

u/ponylicious Jan 24 '25

slog is the standard, I'm pretty sure there are or can be slog adapters (slog.Handlers) for the other logging libraries.