Skip to content

Comments

Support logrus.Field logger in the logrus adapter#793

Merged
ChrisHines merged 1 commit intogo-kit:masterfrom
sagikazarmark:logrus_fieldlogger
Nov 13, 2018
Merged

Support logrus.Field logger in the logrus adapter#793
ChrisHines merged 1 commit intogo-kit:masterfrom
sagikazarmark:logrus_fieldlogger

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"))


// 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