inconshreveable / log15

Structured, composable logging for Go
https://godoc.org/github.com/inconshreveable/log15
Other
1.1k stars 145 forks source link

Support for a kv-generating interface on log arguments #142

Open decibel opened 6 years ago

decibel commented 6 years ago

Use case: I've got a number of pre-defined logging keys that our code should be using; some mandatory, some optional. Since this is a complete set, it would be best to use a struct to define them; that way there's no chance of fat-fingering key names (is it Stack or StackTrace??).

My thought is that an interface like...

type KeyValuer interface {
    KeyValues() []interface{}
}

would satisfy what Record.Ctx wants, and could be identified while processing log arguments. Basically, this would be an exposed version of what Ctx.toArray() does. I think this would also satisfy #25.

A guess another option would be to write a handler that detects when it's been handed a KeyValuer, but that has the disadvantage of requiring the user to still provide some kind of key to keep the number of arguments even.