mailgun / groupcache

Clone of golang/groupcache with TTL and Item Removal support
Apache License 2.0
484 stars 72 forks source link

Remove hard dependency on logrus for logging #42

Closed nathanejohnson closed 2 years ago

nathanejohnson commented 2 years ago

Removes hard dependency on logrus for logging, while providing backwards compatibility via the SetLogger method.

Introduces a Logger interface that others can implement for other structured loggers such as zerolog.

Bumps the golang.org/x/sys dependency since tests fail to run on go 1.18 with the old version.

nathanejohnson commented 2 years ago

So this will slow logging down slightly if using the LogrusLogger versus native logrus, but from a quick POC doing a zerolog implementation as a Logger I get considerably better results:

% go test -bench=.
goos: darwin
goarch: amd64
pkg: github.com/mailgun/groupcache/v2
cpu: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
BenchmarkLogrusLogger-12          363612              3000 ns/op
BenchmarkLogrus-12                412762              2734 ns/op
BenchmarkZeroLogger-12           1000000              1100 ns/op
PASS
ok      github.com/mailgun/groupcache/v2        6.156s

Here is a link to the implementation if you're curious.

https://github.com/nathanejohnson/groupcache/blob/feature/zerolog/logger.go#L98

nathanejohnson commented 2 years ago

for what it's worth, I've opened a PR with upstream logrus around the x/sys dep:

https://github.com/sirupsen/logrus/pull/1333