martian
martian copied to clipboard
logging: add tracing to log calls to aid in debugging
In the martian.Context
for each http.Request
is a short lived unique(ish) ID. It would be helpful for debugging to be able to include this "trace ID" in every log line that occurs to be able to follow the execution/modification of a request/response.
My initial idea is that a package creates a Logger instance that it holds and passes the martian.Context
to that will obtain the information it needs and reformat as appropriate.
package mypkg
var log = martian.NewLogger("mypkg.Modifier")
type Modifier struct {
...
}
func (m *Modifier) ModifyRequest(req *http.Request) error {
ctx := martian.NewContext(req)
// Logs with ctx.ID(), the package and the formatted log line.
log.Debugf(ctx, "modifying request: %s", req.URL)
...
return nil
}