log15 icon indicating copy to clipboard operation
log15 copied to clipboard

Support for a kv-generating interface on log arguments

Open decibel opened this issue 8 years ago • 0 comments

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.

decibel avatar Jan 20 '18 21:01 decibel