You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've seen Add WithContext PR has been merged but there isn't really a descriptive/helpful documentation on it.
Contains the context set by the user. Useful for hook processing etc.
For example, is it going to allow us to add some custom fields to logs with dynamic values per request? Is it used to fetch data from context and do what ever we want to do with it? If so, how, any example please.
Thanks
The text was updated successfully, but these errors were encountered:
Currently I am using a custom logrus wrapper that contains function below to add default fields to every log and they come from context. Have a reinvented the wheal or logrus WithContext has no ability for such logic?
......funcMyWithContext(ctx context.Context) *logrus.Entry {
// Static value for every requestsl:=logrus.WithField("static_field", "always same")
// Dynamic values per requestfor_, k:=range []string{"request_id", "user_id"} {
v:=ctx.Value(k)
ifv==nil {
v=""
}
l=l.WithField(k, fmt.Sprintf("%v", v))
}
returnl
}
The context has been added for hooks processing. There is no field automatically added from a context. Someone may have implemented that as a hook, but I'm unaware of it.
Depending on the hook implementation, some used api may require to have a context so it makes sense to use the one from the caller for deadline management rather than using an empty one.
Hi,
I've seen Add WithContext PR has been merged but there isn't really a descriptive/helpful documentation on it.
For example, is it going to allow us to add some custom fields to logs with dynamic values per request? Is it used to fetch data from context and do what ever we want to do with it? If so, how, any example please.
Thanks
The text was updated successfully, but these errors were encountered: