Skip to content

Comments

Add logrus adapter for Logger interface (#752)#759

Merged
ChrisHines merged 4 commits intogo-kit:masterfrom
aswinmprabhu:master
Sep 18, 2018
Merged

Add logrus adapter for Logger interface (#752)#759
ChrisHines merged 4 commits intogo-kit:masterfrom
aswinmprabhu:master

Conversation

@aswinmprabhu
Copy link
Contributor

No description provided.

// NewLogrusLogger returns a logger that logs the keyvals to Writer
// with a time stamp at the logrus.InfoLevel
func NewLogrusLogger(w io.Writer) Logger {
newLogger := logrus.New()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the main use case for this package is to adapt a *logrus.Logger used as the main logger in an application so it can be passed to code that expects a Go kit log.Logger. For that use case this constructor would be more flexible if it were declared as NewLogrusLogger(logger *logrus.Logger) log.Logger.

This form allows the main application to configure logrus however it wants and then simply adapt it to the Go kit log.Logger interface.

"fmt"
"io"

"github.com/sirupsen/logrus"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want the base Go kit log package to have a dependency on logrus. The logrus adapter should be in its own package in a subdirectory. I suggest it go in github.com/go-kit/kit/log/logrus.

@@ -0,0 +1,31 @@
package log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the code is moved into the log/logrus package, the package name here should also be logrus.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add at least a sentence of package documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please clarify on what you mean by package documentation? I looked at other packages like endpoint.go and metrics.go and didn't see anything other that function and type docs.

Copy link
Member

@ChrisHines ChrisHines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed response and the way I split comments between stand alone comments and review comments. I was trying the new VS Code Github PR extension and didn't realize right away that it didn't support grouping comments into a single review (or I don't know how to use it right yet).

@@ -0,0 +1,31 @@
package log
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add at least a sentence of package documentation.

Copy link
Member

@ChrisHines ChrisHines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good now. Just a couple fixes in the docs and this should be ready to merge.

Copy link
Member

@ChrisHines ChrisHines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

@ChrisHines ChrisHines merged commit 9890679 into go-kit:master Sep 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants