-
Notifications
You must be signed in to change notification settings - Fork 51
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
Decoupled logrus and added a logger interface #12
Conversation
@a8m Added a logger interface and a couple of implementations (logrus and stdlib). Verified that both work. I think the lib should only log info and error messages and not try to deal with all possible "levels". I'm not sure if the lib should include implementations for popular loggers such as logurs, zap, etc as it would pull in those dependencies whether the users need them or not. Probably they should be published as independent packages. Thoughts? |
8ab4460
to
de2fc25
Compare
de2fc25
to
d41599a
Compare
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.
Hey @owais, thanks so much for your contribution. I've added a few comments.
Another thing, imo it makes more sense to leave all logging code under the root (producer
) package.
As a user of this package, I prefer to not import a generic/common package (e.g: logging
) that will conflict with other packages.
logger.go
Outdated
} | ||
|
||
// Value represents a key:value pair used by the Logger interface | ||
type Value struct { |
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.
I would rename this struct into something like LogEntry
, since it's a bit confusing that it's under producer
namespace.
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.
Sure. I moved it from the loggers package to top level but didn't rename,.
logger.go
Outdated
// Logger represents a simple interface used by kinesis-producer to handle logging | ||
type Logger interface { | ||
Info(msg string, values ...Value) | ||
Error(msg string, err error, values ...Value) |
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.
Error(msg string, err error, values ...Value) | |
Info(args ...interface{}) | |
Error(args ...interface{}) |
What do you say about changing the interface signature to something like this? this will save the Value
entry and the logrus/zap implementations.
You can even make it a field-logger by treat the args
param as a list of key-value pairs.
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.
I personally don't like it as almost all loggers at least expect a string so taking interface{} where you know you need a string doesn't sound too good to me. Also, I think having a struct to define a key value pair is better than an even number of args and then grouping them inside the function. I think it's cleaner for both the API and the internal implementation. I don't see much value in doing it but you are maintaining the code so I can do what makes your workflow better.
The reason I put it inside a sub-package was to avoid making zap and logrus dependencies (in near future). I was thinking that |
That said, I can move it to the root package for now and we can move it back or out of the repo if needed/wanted in future. |
d003433
to
35ec22c
Compare
- `producer.Config` now takes a producer.Logger interface instead of a Logrus instance. - If not logger is provided to config, producer uses a standard library logger by default (`producer.StandardLogger`) - `loggers` sub package ships implementations for zap and logrus.
35ec22c
to
2e8333b
Compare
@a8m Incorporated some suggestions. Let me know your decision on root vs sub-package for logger implementations. I personally think it should actually be like the following but am open to moving everything to root'
|
I agree with this, and that's why I suggested creating an interface that common log packages support by default, and we should add only the default implementation, which is the std-log. About directories structure, my only problem with this is that I don't want to create a package with common name, or to conflict with logrus or zap, so people will need to alias it to something else. |
OK, makes sense. In that case, we could use a less common but somewhat ugly names. Something like:
|
Go's packages are usually lowercased with no underscore or mixedCaps (ref). But yeah, I agree, |
Thanks for the contribution and your patient @owais. |
Fixed #10