-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
logger with context ? #1541
Comments
you can implement your own logger. Just implement the Logger interface as defined in https://github.com/olivere/elastic/blob/release-branch.v7/logger.go. Hope that helps. |
@olivere that does not meet the problem. (we have implement own logger with zap) In our system, there is a "requestId" for per-request for logging, so we can combine multiple log for the same request. if there is an error, |
Ah. I see. Let me have another look at it. |
Yep. Passing the context as part of the logging should be fine. Just need to make it backwards compatible. As for tracing, there's already support for |
This commit adds a `LoggerWithContext` interface that extends the `Logger` interface by a method `PrintfWithContext` that, when implemented, is called instead of the `Printf` method of the `Logger` interface. The purpose of `PrintfWithContext` is to receive the current context under which the logging happens. Notice that this doesn't always have to be request-scoped, i.e. an actual API call from a user. It may also be from an internal state or process, e.g. Bulk processor or node health. Close #1541
This commit adds a `LoggerWithContext` interface that extends the `Logger` interface by a method `PrintfWithContext` that, when implemented, is called instead of the `Printf` method of the `Logger` interface. The purpose of `PrintfWithContext` is to receive the current context under which the logging happens. Notice that this doesn't always have to be request-scoped, i.e. an actual API call from a user. It may also be from an internal state or process, e.g. Bulk processor or node health. Close #1541
#1542 should give you what you want. I will leave it around until 7.0.30 will be released. There's a few things I don't like about that PR, but yeah. Maybe I'll find a cleaner solution. If #1542 will be merged, you only have to implement |
@olivere thanks ! |
@olivere |
Very probably not. This repository is effectively deprecated and dormant. Please switch to the official client. |
Which version of Elastic are you using?
[ x ] elastic.v7 (for Elasticsearch 7.x)
[ ] elastic.v6 (for Elasticsearch 6.x)
[ ] elastic.v5 (for Elasticsearch 5.x)
[ ] elastic.v3 (for Elasticsearch 2.x)
[ ] elastic.v2 (for Elasticsearch 1.x)
Please describe the expected behavior
Can Logger support Context ? Because it's usefully for tracing,add requestId etc for a request.
Please describe the actual behavior
Any steps to reproduce the behavior?
The text was updated successfully, but these errors were encountered: