Exemple #1
0
func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// Misbehave by mutating request object to verify that this does not affect
	// logs
	r.URL.Path = "/HandlerMutatedRequest"
	if h.Hijack {
		w.(http.Hijacker).Hijack()
	}
	if h.Status != 0 {
		w.WriteHeader(h.Status)
	}
	if h.Message != "" {
		fmt.Fprintf(w, "%s", h.Message)
	}
	if h.LogExtra != "" {
		fmt.Fprintf(weblogs.Writer(r), " %s", h.LogExtra)
	}
	values := weblogs.Values(r)
	if values != nil {
		if h.Field1 != "" {
			values["field1"] = h.Field1
		}
		if h.Field2 != "" {
			values["field2"] = h.Field2
		}
	}
	if h.Clock != nil {
		h.Clock.AddMillis(h.ElapsedMillis)
	}
}
Exemple #2
0
func TestUnwrappedCallToValues(t *testing.T) {
	if weblogs.Values(newRequest(
		"192.168.5.1:3333", "GET", "/foo/bar?query=tall")) != nil {
		t.Error("Expected unwrapped weblogs.Values call to return nil")
	}
}
Exemple #3
0
// SetUserName sets the current user name for logging.
func SetUserName(r *http.Request, name string) {
	values := weblogs.Values(r)
	if values != nil {
		values[kUserName] = name
	}
}