title: Logging All HTTP Request and Response from done through an HTTP Client
body: <p>I have the following simple <code>http.Client</code>:</p>
  <pre class="lang-golang prettyprint-override"><code>import (
   &quot;net/http&quot;
   &quot;log&quot;
  )
  ...
  func main() {
     ...
     link = &quot;http://example.com&quot;
     method = &quot;GET&quot;
     req, _ := http.NewRequest(method, link, nil)
  
     client := &amp;http.Client{}
  
     myZapLogger.Info(&quot;Sending a %s request to %s\n&quot;, method, link)
  
     resp, err := client.Do(req)
     if err != nil {
        myZapLogger.Error(..., err) // I'm logging rather than fatal-ing or so
     } else { 
        myZapLogger.Info(&quot;Received a %d on request X&quot;, resp.StatusCode)
     }
     ...
  }
  
  ...
  </code></pre>
  <p>I was looking for a way to do the above for each request through a hook (or so), so that it's triggered automatically each time. I can write a function the encloses all that, but in a case where I'm passing an http client to some other package, I wouldn't be able to control/log such requests that way (e.g. <code>aws-go-sdk</code>).</p>
  <p>Is there a way to do this through contexts or attaching hooks to the client?</p>
  <p>Thanks</p>