1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

feat: add a new wrapper logger for debugging (#8436)

* feat: add a new debug logger

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: duplicate first messages

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add checks in info()

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* add debug logger to notary package

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update info func

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add error func

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: update wrapper to use right fmt functions

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: use sprintln not sprint

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: remove V(4)

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* refactor: removed common code

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update pkg/notary/log.go

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update pkg/notary/log.go

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update pkg/notary/log.go

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: update names

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update pkg/notary/log.go

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: add verbosity levels

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* Update pkg/notary/log.go

Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* fix: lint

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

* feat: use errors new

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>

---------

Signed-off-by: Vishal Choudhary <sendtovishalchoudhary@gmail.com>
Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Vishal Choudhary 2023-09-19 01:17:59 +05:30 committed by GitHub
parent b6c959bfac
commit 828807bddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 1 deletions

87
pkg/notary/log.go Normal file
View file

@ -0,0 +1,87 @@
package notary
import (
"errors"
"fmt"
"github.com/go-logr/logr"
notationlog "github.com/notaryproject/notation-go/log"
)
func NotaryLoggerAdapter(logger logr.Logger) notationlog.Logger {
return &notaryLoggerAdapter{
logger: logger.V(4),
}
}
type notaryLoggerAdapter struct {
logger logr.Logger
}
func (nla *notaryLoggerAdapter) Debug(args ...interface{}) {
nla.info(0, args...)
}
func (nla *notaryLoggerAdapter) Debugf(format string, args ...interface{}) {
nla.infof(0, format, args...)
}
func (nla *notaryLoggerAdapter) Debugln(args ...interface{}) {
nla.infoln(0, args...)
}
func (nla *notaryLoggerAdapter) Info(args ...interface{}) {
nla.info(1, args...)
}
func (nla *notaryLoggerAdapter) Infof(format string, args ...interface{}) {
nla.infof(1, format, args...)
}
func (nla *notaryLoggerAdapter) Infoln(args ...interface{}) {
nla.infoln(1, args...)
}
func (nla *notaryLoggerAdapter) Warn(args ...interface{}) {
nla.info(2, args...)
}
func (nla *notaryLoggerAdapter) Warnf(format string, args ...interface{}) {
nla.infof(2, format, args...)
}
func (nla *notaryLoggerAdapter) Warnln(args ...interface{}) {
nla.infoln(2, args...)
}
func (nla *notaryLoggerAdapter) Error(args ...interface{}) {
nla.logger.Error(errors.New(fmt.Sprint(args...)), "")
}
func (nla *notaryLoggerAdapter) Errorf(format string, args ...interface{}) {
nla.logger.Error(fmt.Errorf(format, args...), "")
}
func (nla *notaryLoggerAdapter) Errorln(args ...interface{}) {
nla.logger.Error(errors.New(fmt.Sprintln(args...)), "")
}
func (nla *notaryLoggerAdapter) info(level int, args ...interface{}) {
nla.log(level, fmt.Sprint(args...))
}
func (nla *notaryLoggerAdapter) infof(level int, format string, args ...interface{}) {
nla.log(level, fmt.Sprintf(format, args...))
}
func (nla *notaryLoggerAdapter) infoln(level int, args ...interface{}) {
nla.log(level, fmt.Sprintln(args...))
}
func (nla *notaryLoggerAdapter) log(level int, message string) {
logger := nla.logger
if level > 0 {
logger = logger.V(level)
}
logger.Info(message)
}

View file

@ -15,6 +15,7 @@ import (
_ "github.com/notaryproject/notation-core-go/signature/cose"
_ "github.com/notaryproject/notation-core-go/signature/jws"
"github.com/notaryproject/notation-go"
notationlog "github.com/notaryproject/notation-go/log"
"github.com/notaryproject/notation-go/verifier"
"github.com/notaryproject/notation-go/verifier/trustpolicy"
"github.com/opencontainers/go-digest"
@ -68,7 +69,7 @@ func (v *notaryVerifier) VerifySignature(ctx context.Context, opts images.Option
MaxSignatureAttempts: 10,
}
targetDesc, outcomes, err := notation.Verify(context.TODO(), notationVerifier, parsedRef.Repo, remoteVerifyOptions)
targetDesc, outcomes, err := notation.Verify(notationlog.WithLogger(ctx, NotaryLoggerAdapter(v.log.WithName("Notary Verifier Debug"))), notationVerifier, parsedRef.Repo, remoteVerifyOptions)
if err != nil {
return nil, errors.Wrapf(err, "failed to verify %s", ref)
}