mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +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(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = ["log_test.go"],
|
srcs = ["httplog_test.go"],
|
||||||
library = ":go_default_library",
|
library = ":go_default_library",
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
)
|
)
|
||||||
@ -19,7 +19,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"doc.go",
|
"doc.go",
|
||||||
"log.go",
|
"httplog.go",
|
||||||
],
|
],
|
||||||
tags = ["automanaged"],
|
tags = ["automanaged"],
|
||||||
deps = ["//vendor/github.com/golang/glog:go_default_library"],
|
deps = ["//vendor/github.com/golang/glog:go_default_library"],
|
||||||
|
@ -27,18 +27,6 @@ import (
|
|||||||
"github.com/golang/glog"
|
"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.
|
// StacktracePred returns true if a stacktrace should be logged for this status.
|
||||||
type StacktracePred func(httpStatus int) (logStacktrace bool)
|
type StacktracePred func(httpStatus int) (logStacktrace bool)
|
||||||
|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package httplog
|
package httplog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"reflect"
|
"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) {
|
func TestStatusIsNot(t *testing.T) {
|
||||||
statusTestTable := []struct {
|
statusTestTable := []struct {
|
||||||
status int
|
status int
|
Loading…
Reference in New Issue
Block a user