Skip to content
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

Consider changing how keys are namespaced #198

Open
thockin opened this issue Aug 4, 2023 · 0 comments
Open

Consider changing how keys are namespaced #198

thockin opened this issue Aug 4, 2023 · 0 comments
Assignees

Comments

@thockin
Copy link
Contributor

thockin commented Aug 4, 2023

#196 (comment)

Many/Most LogSink impls (especially strict JSON and similar) inject "special" keys into the log output ("err" in case of Error(), "msg", "caller", etc). It's possible for these to collide with user-provided keys. Mostly we say "well, it was documented" (and hopefully it was), but this sort of requires callers to know which LogSink is in use, which is unfortunate.

How could we solve this?

We could choose to "group" keys (we didn't in the past, but there's always v2 :). We'd still have to pick a name for the group in the root keyspace, e.g.

{ "cleverName": { "msg": "the message", "ts": "08:45:25", "caller": { "file": "file.go", "line": "123" } }, "log1": 123, "log2": 456 }

We could name-prefix keys (e.g. "logr/name") but it seems unfortunate to embed "logr" into the keyspace. E.g.:

{ "logr/msg": "the message", "logr/ts": "08:45:25", "logr/caller": { "file": "file.go", "line": "123" } }, "log1": 123, "log2": 456 }

We could puntuation-prefix keys (e.g. keys which start with "_" are reserved), then we can argue about "_foo" vs "@foo" vs "%foo".

{ "_msg": "the message", "_ts": "08:45:25", "_caller": { "file": "file.go", "line": "123" } }, "log1": 123, "log2": 456 }

We could make the prefix or key user-defined, and pass it around through Logger instances, and except LogSinks to respect it.

We could group or prefix all the user-provided keys (again, maybe configurable?). E.g.

{ "msg": "the message", "ts": "08:45:25", "caller": { "file": "file.go", "line": "123" } }, "data": { "log1": 123, "log2": 456 } }
@thockin thockin mentioned this issue Aug 4, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants