-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Logger a concrete type instead of an interface #270
Conversation
`zapcore.Facility` is the extension point we're offering to third-party developers, so there's no need to make the logger an interface. In fact, an interface will be *more* constraining, since we won't be able to add any methods after version 1.0. Along the way, this fixes our woes with `AddCaller` not working properly (#40).
@akshayjshah, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jcorbin, @akabos and @prashantv to be potential reviewers. |
I REALLY don't like this, if I could I would HIGHLY fight against this change. I think that how golang made their Logger a struct is highly limiting - there's a lot of instances where writers of libraries want to abstract away what type of logging package is used, and end up wanting an interface anyways, and the overhead vtable lookup cost is very small. https://godoc.org/github.com/sirupsen/logrus#StdLogger |
@peter-edge if library authors want to abstract the logger they use, isn't it their business to define the Logger interface that library can consume? I assume the use case you are describing is: I'm a library, I want to log stuff, I want to use zap as my default logging library, but I want to allow others who use me to set a different logger. In that use case, can't I ( the library's author ) define an interface which zap.Logger happens to conforms to? That's a common pattern. You see that a lot in packages which use the stdlogger by default. |
It's a common pattern that most libraries (especially written by new gophers) ignore. I've seen way too many libraries locked into https://github.com/golang/glog because "oh google is using it, it must be the way to go" (and not realizing how much glog does) to not be wary of this pattern. I think one of the biggest mistakes golang made in the stdlib was to make Logger a struct, not an interface - it encourages this. Zap could become the new glog in that sense, and I'm really nervous of that. If anything, make Logger an interface (so people gravitate towards that), and then have an UnsugaredLogger or something. |
Also this is why I added grpclog back in the way - a lot of people, even experienced gophers, do the lock-in, and then it messes with everyone. |
Peter and I are both internal to Uber, so we get to cheat and video chat :) For posterity, conclusions from our discussion:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be the biggest pain point for pre 1.0 -> 1.0 conversions: a global s/zap.Logger/*zap.Logger/
(I mean sure, the yet to settle construction shape changes too, but that's at least a contained change)
Luckily, that change is go fix-able. |
`zapcore.Facility` is the extension point we're offering to third-party developers, so there's no need to make the logger an interface. In fact, an interface will be *more* constraining, since we won't be able to add any methods after version 1.0. Along the way, this fixes our woes with `AddCaller` not working properly (#40).
zapcore.Facility
is the extension point we're offering to third-partydevelopers, so there's no need to make the logger an interface. In fact, an
interface will be more constraining, since we won't be able to add any methods
after version 1.0.
Along the way, this fixes our woes with
AddCaller
not working properly (#40).