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
s := logr.ToSlog(myLogger)
s.With("a", 1) // calls Handler.WithAttrs(), which calls logr WithValues("a", 1)
s = s.WithGroup("g") // calls Handler.WithGroup("g"), which saves "g" as a prefix
s.With("b", 2) // calls Handler.WithAttrs(), which calls logr WithValues("g.b", 2)
s.Info("the msg", "c", 3) // calls Handler.Handle, which calls logr.Info("the msg", "g.c", 3)
Unless the LogSink is very clever (parse all keys and re-group, which I would not suggest doing), the result will be something like {"msg": "the msg", "a": 1, "g.b": 2, "g.c": 3}, when what the user clearly wanted was more like {"msg": "the msg", "a": 1, "g": {"b": 2, "c": 3}}
If we teach logr to have a "group" construct, maybe we can make it work:
s := logr.ToSlog(myLogger)
s.With("a", 1) // calls Handler.WithAttrs(), which calls logr WithValues("a", 1)
s = s.WithGroup("g") // calls Handler.WithGroup("g"), which calls logr WithGroup("g")
s.With("b", 2) // calls Handler.WithAttrs(), which calls logr WithValues("b", 2)
s.Info("the msg", "c", 3) // calls Handler.Handle, which calls logr.Info("the msg", "c", 3)
The text was updated successfully, but these errors were encountered:
#196 (comment)
Consider:
Unless the LogSink is very clever (parse all keys and re-group, which I would not suggest doing), the result will be something like
{"msg": "the msg", "a": 1, "g.b": 2, "g.c": 3}
, when what the user clearly wanted was more like{"msg": "the msg", "a": 1, "g": {"b": 2, "c": 3}}
If we teach logr to have a "group" construct, maybe we can make it work:
The text was updated successfully, but these errors were encountered: