Skip to content
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

Support logrus.Field logger in the logrus adapter #793

Merged
merged 1 commit into from
Nov 13, 2018
Merged

Support logrus.Field logger in the logrus adapter #793

merged 1 commit into from
Nov 13, 2018

Conversation

sagikazarmark
Copy link
Contributor

Logrus exposes an interface FieldLogger. It is usually better to hint against this interface, because the main logger instance returns a different type for loggers preannotated with structured context (namely *Entry). This way one can do this:

logger := kitlogrus.NewLogrusLogger(logrusLogger.With("component", "my_component"))

}

var errMissingValue = errors.New("(MISSING)")

// NewLogrusLogger returns a go-kit log.Logger that sends log events to a Logrus logger.
func NewLogrusLogger(logger *logrus.Logger) log.Logger {
// NewLogrusLogger returns a go-kit log.FieldLogger that sends log events to a Logrus logger.
Copy link
Member

Choose a reason for hiding this comment

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

The function still returns a go-kit log.Logger. It's the input type that has changed to accept the logrus.FieldLogger type.

The phrase "... to a Logrus logger" still seems accurate and perhaps more to the point. Ending with "... to a logrus.FieldLogger" would be more precise, but just repeating what the code says. I'm not a Logrus user, so I'm not sure which phrasing is more intuitive for that user base. Thoughts?

Suggested change
// NewLogrusLogger returns a go-kit log.FieldLogger that sends log events to a Logrus logger.
// NewLogrusLogger returns a go-kit log.Logger that sends log events to a Logrus logger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, good catch, it was kinda automatic change. 🙂

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 0f5dcea into go-kit:master Nov 13, 2018
@sagikazarmark sagikazarmark deleted the logrus_fieldlogger branch November 13, 2018 15:36
@sagikazarmark
Copy link
Contributor Author

Thanks!

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.

2 participants