1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-29 02:45:06 +00:00

feat: add webhook server logger (#5063)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2022-10-19 15:12:55 +02:00 committed by GitHub
parent a0bcf7a966
commit 73712f3738
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -4,7 +4,10 @@ import (
"context"
"errors"
"flag"
"io"
stdlog "log"
"os"
"strings"
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
@ -129,3 +132,17 @@ func Background() context.Context {
func TODO() context.Context {
return IntoContext(context.TODO(), GlobalLogger())
}
type writerAdapter struct {
io.Writer
logger logr.Logger
}
func (a *writerAdapter) Write(p []byte) (int, error) {
a.logger.Info(strings.TrimSuffix(string(p), "\n"))
return len(p), nil
}
func StdLogger(logger logr.Logger, prefix string) *stdlog.Logger {
return stdlog.New(&writerAdapter{logger: logger}, prefix, stdlog.LstdFlags)
}

View file

@ -11,6 +11,7 @@ import (
"github.com/julienschmidt/httprouter"
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
"github.com/kyverno/kyverno/pkg/config"
"github.com/kyverno/kyverno/pkg/logging"
"github.com/kyverno/kyverno/pkg/toggle"
"github.com/kyverno/kyverno/pkg/utils"
admissionutils "github.com/kyverno/kyverno/pkg/utils/admission"
@ -103,6 +104,7 @@ func NewServer(
WriteTimeout: 30 * time.Second,
ReadHeaderTimeout: 30 * time.Second,
IdleTimeout: 5 * time.Minute,
ErrorLog: logging.StdLogger(logger.WithName("server"), ""),
},
mwcClient: mwcClient,
vwcClient: vwcClient,