Skip to content

Commit

Permalink
feat: add support for Shared Policy Groups
Browse files Browse the repository at this point in the history
see: https://gravitee.atlassian.net/browse/GKO-912

fix: redirect standard go logs to zap
  • Loading branch information
a-cordier authored and kamiiiel committed Jan 17, 2025
1 parent fc425cd commit 169b65a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package log
import (
"context"
"fmt"
"strings"

stdLog "log"

"github.com/go-logr/zapr"
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/core"
Expand All @@ -35,33 +38,39 @@ type raw struct {
sink *zap.Logger
}

func (w *raw) Write(p []byte) (int, error) {
message := strings.TrimSpace(string(p))
w.sink.Info(message)
return len(p), nil
}

var Global raw

func (w raw) Debug(message string) {
func (w *raw) Debug(message string) {
w.sink.Debug(message)
}

func (w raw) Info(message string) {
func (w *raw) Info(message string) {
w.sink.Info(message)
}

func (w raw) Infof(message string, args ...any) {
func (w *raw) Infof(message string, args ...any) {
w.sink.Info(fmt.Sprintf(message, args...))
}

func (w raw) Debugf(message string, args ...any) {
func (w *raw) Debugf(message string, args ...any) {
w.sink.Debug(fmt.Sprintf(message, args...))
}

func (w raw) Warn(message string) {
func (w *raw) Warn(message string) {
w.sink.Warn(message)
}

func (w raw) Error(err error, message string) {
func (w *raw) Error(err error, message string) {
w.sink.Error(message, zap.Error(err))
}

func (w raw) Errorf(err error, message string, args ...any) {
func (w *raw) Errorf(err error, message string, args ...any) {
w.sink.Error(fmt.Sprintf(message, args...), zap.Error(err))
}

Expand Down Expand Up @@ -152,6 +161,7 @@ func init() {
log.SetLogger(logger)
kLog.SetLogger(logger)
Global = raw{sink: sink}
stdLog.SetOutput(&Global)
}

func getEncoding() string {
Expand Down

0 comments on commit 169b65a

Please sign in to comment.