For the following snippet of code :
package main
import(
log "github.com/Sirupsen/logrus"
)
type A struct {
a int
b string
}
func main() {
z := A{a: 1, b: "Test"}
log.Infof("%+v", z)
log.WithFields(log.Fields{"A": z}).Info("Value is ")
}
The output is
INFO[0000] {a:1 b:Test}
INFO[0000] Value is A={1 Test}
What do I do with "WithFields" so that in the second line, the output shows fieldnames as well ?
i.e. I would like the output to be
INFO[0000] {a:1 b:Test}
INFO[0000] Value is A={a:1 b:Test}
We are trying to standardize on using "WithFields" in our codebase, hence the question.
Implement Stringer interface for this type.
Thanks !
It gets tedious for a large project with many many types ....
Look at fmt.Sprintf
I do this (what prev comment was alluding to I think):
log.WithFields(log.Fields{
"user": fmt.Sprintf("%+v", u),
}).Debug("Found User")
Most helpful comment
I do this (what prev comment was alluding to I think):