-
Notifications
You must be signed in to change notification settings - Fork 218
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
Child loggers #22
Comments
@dims do you have any thoughts around this? I'm happy to start some work on it if there is some consensus on how to proceed on it and some guidance. |
isn't this solved by the structured logging proposed by https://github.com/go-logr/logr |
Maybe? I haven't looked at logr yet, although in this proposal the child logger would be instantiated from the |
This looks very similar to how we use logr in controller-runtime. You can check out our code (sigs.k8s.io/controller-runtime/pkg/runtime/log), but the TL;DR is: logr defines two methods on a // instantiates a new sub-logger, appending the name to the set of names
WithName(string) logr.Logger
// instantiates a new logger, adding/setting the given values to the set of values for this logger
WithValues(kvPairs ...interface{}) logr.Logger Then, in the CR package mentioned above, we define // magically set up some stuff that allows delayed setting of the actual logr.Logger implementation
var Log logr.Logger = [some magic] This enables patterns like import logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
// in a controller
var log = logf.Log.WithName("controllers").WithName("foo-controller")
// later on
func (r *FooController) Reconcile(req reconcile.Request) (reconcile.Response, error) {
log := log.WithValues("foo", req.NamespacedName)
log.Info("starting reconcile")]
// more stuff
} |
@DirectXMan12 Thanks for the example, that looks pretty much what I was thinking! Any thoughts on bringing that logic in |
yep, this was pretty much what i meant with.
|
i somehow think this should be on the klog implementer side. |
I think we need to figure out how klog relates to logr at some point. One option is that klog implements logr's interfaces, which allows us to keep kube libraries logging-implementation-agnostic (since logr is just an interface). That's what I lean towards, but that definitely needs broader discussion. |
@DirectXMan12 who should we loop in for this discussion? (just throw it out on -dev mailing list)? |
it's probably a -dev or KEP-worth discussion, yeah. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle stale |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
/remove-lifecycle rotten |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
@vincepri does the current implementation of klogr meet your needs for this issue? |
That’s probably ok for now, we can close this one out /close |
@vincepri: Closing this issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/kind feature
Describe the solution you'd like
A common use case for loggers is to provide a default context. An example is to prepend some common values to each log line. I've seen other loggers are able to create a child logger of some sort with a predefined set of variables which are used as suffix for each log line.
I'd imagine this approach to have some sort of limitations, for example how many variables are allowed to be set as context. This approach would have the following requirements:
Thoughts?
The text was updated successfully, but these errors were encountered: