Add logger interface and stop relying on Logrus directly#1408
Conversation
6c82855 to
58c61e1
Compare
58c61e1 to
be581fa
Compare
ericchiang
left a comment
There was a problem hiding this comment.
thanks for doing this!
|
@ericchiang let me answer here, as most of your comments are related to a single problem. The interface I added includes the following function: WithField(key string, value interface{}) LoggerThe same function in Logrus looks like this: WithField(key string, value interface{}) *EntryThe problem is the interface has a reference to itself in order to remove dependency on Logrus. Because of this:
That WithField function is used in a single place: Line 489 in 8935a14 It's inside the library part, that's why I added the function to the interface. But I didn't really have any heuristics about the implementation, I just created and implemented the interface. So if dex code is not supposed to be used from external packages, the logger can be moved to an internal package (although then dex code should probably be moved to internal as well). In case WithField method can somehow be replaced, then the interface wouldn't have to reference itself, it could be moved to an internal package and logrus would satisfy the interface without a wrapper. |
|
I vote we drop our uses of |
|
Well, I'm generally in favor of structured logging, but given there is a single place where it is used right now, I'm inclined to remove it as well, at least for now. |
|
@ericchiang I removed the wrapper type and the structural logging. I still think if any dex code is supposed to be called externally, then the logger interface should be exported too, but if you want, I can move it under |
ericchiang
left a comment
There was a problem hiding this comment.
one nit.
dex code shouldn't be imported by other projects. We change the API and refactor all the time (like what this PR is doing). I won't block this PR on pkg/log instead of internal/log though.
lgtm, thanks for helping out here! 😃
Add logger interface and stop relying on Logrus directly
Fixes #868
Before merging: I placed the interface in
pkg/logpackage because that's the standard place for reusable stuff. If you want it somewhere else, let me know.Further (possible) improvements:
WithFieldand replace it with a constructor (used in one place only). It would result in a cleaner interface which does not reference itself, thus external implementations would not have to import dex itself to provide integration