| // Copyright 2017 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func newLogger(t http.RoundTripper) http.RoundTripper { |
| return &loggingTransport{transport: t} |
| type loggingTransport struct { |
| transport http.RoundTripper |
| func (t *loggingTransport) RoundTrip(r *http.Request) (*http.Response, error) { |
| fmt.Fprintf(os.Stderr, "HTTP: %s %s+ %s\n", timeFormat1(start), t.active, r.URL) |
| t.active = append(t.active, '|') |
| resp, err := t.transport.RoundTrip(r) |
| if i := strings.LastIndex(last, "/"); i >= 0 { |
| display += " " + resp.Status |
| display += " error: " + err.Error() |
| fmt.Fprintf(os.Stderr, "HTTP: %s %s %s (%.3fs)\n", timeFormat1(now), t.active, display, now.Sub(start).Seconds()) |
| for n%4 == 0 && n >= 4 && t.active[n-1] == ' ' && t.active[n-2] == ' ' && t.active[n-3] == ' ' && t.active[n-4] == ' ' { |
| t.active = t.active[:n-4] |
| func timeFormat1(t time.Time) string { |
| return t.Format("15:04:05.000") |