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
contrib/sirupsen/logrus: Add context logging hook #1240
Conversation
//Pass the current context to the logger | ||
cLog := logrus.WithContext(sctx) | ||
//Log as desired using the context-aware logger | ||
cLog.Info("Completed some work!") |
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.
Can we use // Output:
here? (https://go.dev/blog/examples)
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.
Ahh neat! I've never used // Output:
before.
It seems to make the example a bit more clunky as it means that the output has to be set to stdout and the time overridden to a fixed value. I've pushed up the change with the Output
validation, let me know if you think it's not worth the extra couple lines of complexity. I'm leaning towards it's not worth it given there's a unit test that validates the Hook
method already and my hope for the example was it's mostly copy/paste for users.
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 think this is great actually. But frankly I was expecting the comment to be just below the log call that causes it. But perhaps I don't fully understand how Output:
works. Disclaimer: I've never used it.
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 agree this is a long example, even more so with the suggested tracer start & stop, but I think it's fine. It's mostly boilerplate and with actual usage its less. Nice work.
//Pass the current context to the logger | ||
cLog := logrus.WithContext(sctx) | ||
//Log as desired using the context-aware logger | ||
cLog.Info("Completed some work!") |
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 think this is great actually. But frankly I was expecting the comment to be just below the log call that causes it. But perhaps I don't fully understand how Output:
works. Disclaimer: I've never used it.
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.
Nice!
This adds a hook for the
logrus
logging package. This makes it a bit easier to connect logs to their related span (as brought up in issue #936.It doesn't seem like a new external API is needed, and due to the nature of context / golang in general it doesn't seem like there's any way to make it more ergonomic.
I tested this in the staging environment and was able to connect logs to their related spans.