samber / slog-gin

🚨 Gin middleware for slog logger
https://pkg.go.dev/github.com/samber/slog-gin
MIT License
89 stars 13 forks source link

Allow parsing of latency in desired unit #21

Open manish-baghel opened 3 weeks ago

manish-baghel commented 3 weeks ago

https://github.com/samber/slog-gin/blob/3f56650b1e9cfe502d84e6deb38c501ba3201389/middleware.go#L164

In the above code, I'd like to either override the value or to use an option to parse latency in desired unit for eg. ms. This can be acheived using methods like https://pkg.go.dev/time#Duration.Milliseconds, https://pkg.go.dev/time#Duration.Microseconds, etc.

Or a simpler option for using https://pkg.go.dev/time#Duration.String to return latency in string format

samber commented 3 weeks ago

What slog handler do you use?

Can you add a ReplaceAttr formatter?

I'm not against your proposal, but I'm not sure it is in the scope of this library to handle such customization.