Exemple #1
0
// Called by http.Server
func (lh *loggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	g, err := guid.V4()
	if err != nil {
		msg := "logginghandler: couldn't create request GUID"
		log.Errorln(msg)
		http.Error(w, msg, http.StatusInternalServerError)
		return
	}
	rw := &loggingResponseWriter{g, lh.loglevel, w}
	log.Logf(lh.loglevel, "HTTP(%s) %s from %s for %s", g.Short(), r.Method, r.RemoteAddr, r.URL)
	lh.Handler.ServeHTTP(rw, r)
}
Exemple #2
0
func (lrw *loggingResponseWriter) WriteHeader(i int) {
	log.Logf(lrw.loglevel, "HTTP(%s) writing header %d", lrw.guid.Short(), i)
	lrw.ResponseWriter.WriteHeader(i)
}
Exemple #3
0
func (lrw *loggingResponseWriter) Write(b []byte) (int, error) {
	log.Logf(lrw.loglevel, "HTTP(%s) writing %d bytes", lrw.guid.Short(), len(b))
	return lrw.ResponseWriter.Write(b)
}