Skip to content

Consider changing how keys are namespaced #198

@thockin

Description

@thockin

#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 } }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions