mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #49972 from deads2k/server-37-log
Automatic merge from submit-queue remove dead log handler and increase verbosity We had a handler that no one was using and this bumps the verbosity slightly (2->3) to reduce noise at 2.
This commit is contained in:
commit
804ec9457a
@ -10,7 +10,7 @@ load(
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["log_test.go"],
|
||||
srcs = ["httplog_test.go"],
|
||||
library = ":go_default_library",
|
||||
tags = ["automanaged"],
|
||||
)
|
||||
@ -19,7 +19,7 @@ go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"log.go",
|
||||
"httplog.go",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
deps = ["//vendor/github.com/golang/glog:go_default_library"],
|
||||
|
@ -27,18 +27,6 @@ import (
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// Handler wraps all HTTP calls to delegate with nice logging.
|
||||
// delegate may use LogOf(w).Addf(...) to write additional info to
|
||||
// the per-request log message.
|
||||
//
|
||||
// Intended to wrap calls to your ServeMux.
|
||||
func Handler(delegate http.Handler, pred StacktracePred) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
defer NewLogged(req, &w).StacktraceWhen(pred).Log()
|
||||
delegate.ServeHTTP(w, req)
|
||||
})
|
||||
}
|
||||
|
||||
// StacktracePred returns true if a stacktrace should be logged for this status.
|
||||
type StacktracePred func(httpStatus int) (logStacktrace bool)
|
||||
|
@ -17,7 +17,6 @@ limitations under the License.
|
||||
package httplog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"reflect"
|
||||
@ -38,28 +37,6 @@ func TestDefaultStacktracePred(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandler(t *testing.T) {
|
||||
want := &httptest.ResponseRecorder{
|
||||
HeaderMap: make(http.Header),
|
||||
Body: new(bytes.Buffer),
|
||||
}
|
||||
want.WriteHeader(http.StatusOK)
|
||||
mux := http.NewServeMux()
|
||||
handler := Handler(mux, DefaultStacktracePred)
|
||||
mux.HandleFunc("/kube", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
})
|
||||
req, err := http.NewRequest("GET", "http://example.com/kube", nil)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
handler.ServeHTTP(w, req)
|
||||
if !reflect.DeepEqual(want, w) {
|
||||
t.Errorf("Expected %v, got %v", want, w)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusIsNot(t *testing.T) {
|
||||
statusTestTable := []struct {
|
||||
status int
|
Loading…
Reference in New Issue
Block a user