Closed stanislavkozlovski closed 5 days ago
I also played around with some other ways to write the message - e.g as per this SO suggestion
But it wouldn't work, and when I added a lock - it was 2x slower as well, with more complexity. I figured it's not worth it.
oops... some tests fail
ha ok, I found why some tests were failing. I had removed the
func init() {
initialise(zapcore.InfoLevel, "console", false)
}
method because I thought it was unused. Learning Go as I go...
Looks good!
One of the tests is failing: TestTektiteLoggerReturnsErrorIfGlobalLoggerUninitialized- this is because the logger is initialised in a package init() method. I think you will need to move this test to another package without the init() to get this to work.
From some research, it seems like I can't avoid calling the init() method. I put the test elsewhere too and still the same failure.
So I guess this scenario can never happen - which is good. Now I get why you had the override flag
This patch extends log.go to provide prefix-logging functionality, allowing each file/struct/component to define their own logger that'll get prepended to every log message:
I hacked around with zap's own benchmark suite and ran the suite 3 times comparing against the usual Zap Sugar logger and this Tektite wrapper. Long-story short:
for simple messages (like
"Test logging, but use a somewhat realistic message length. (10))
, it's 2x slower - 58 ns/op to 114 ns/op. This is still better than libraries likeapex/log
that do 639 ns/op,go-kit/kit/log
which does 142 ns/op,logrus
which does 1129 ns/op andslog
which does 140 ns/opfor large messages, like
logger.Infof("%v %v %v %s %v %v %v %v %v %s\n", fakeFmtArgs()...)
, it's roughly the same - 1275 ns/op to 1338 ns/op