I have lots of Conn instances (from net.Dial(), etc.) and when logging, I need to see what’s going on with specific connections, so now I use something like this:
log.Printf("Handling connection %v", conn)
Which prints out a pointer-ish string such as &{{0xc420053030}}. I believe this happens because conn is an interface, right?
What I would like is to use something which would print out:
The exact format is not relevant, just something which would extract this information from the Conn instance - like something which attaches the String() method to conn. What would be the best way to do it?
Using a better logging package would be a good start. You could either write this yourself, or if you want to get back to work (what I suggest) use something like logrus - https://github.com/sirupsen/logrus
With it you should be able to write something like…