rs / zerolog

Zero Allocation JSON Logger
MIT License
10.62k stars 572 forks source link

Enforce no spaces and punctuations for keys on key-value pairs #447

Closed mrwormhole closed 2 years ago

mrwormhole commented 2 years ago

I want to be able to ensure that the keys of key-value pairs don't contain spaces.

The first dumb idea that comes to my mind is, panic. But as you know this would be brutal for all the systems that are using zerolog and mistakenly leaving empty space in their key-value pairs

The whole idea of key-value pairs in a structured log is to be able to query that log piece by its key right?

so I propose a default opinionated way of turning a spaced log into a camelCase format. Notice that I also propose to trim out special punctuations like ":, !, *, &, £, $" etc... from the key

log.Debug().Str("product ID:", "value").Msg("")
{"level":"debug","product ID:":"value","time":"2022-06-22T12:11:12+01:00"}

and I want to enforce it to print internally

{"level":"debug","productID":"value","time":"2022-06-22T12:11:12+01:00"}

other options like train case or snake case also could be considered, however, I do think that camelCase is the best for introspection of logging query systems.

What is the benefit?

Might eventually reduce the mistakes of people creating issues. And prevent wrong usage of structured logging

rs commented 2 years ago

Such logic does not fit into such a generic lib. You are better writing a wrapper with those enforcements.