diff --git a/pkg/distcache/olric-logwriter.go b/pkg/distcache/olric-logwriter.go new file mode 100644 index 0000000000..78b0036be7 --- /dev/null +++ b/pkg/distcache/olric-logwriter.go @@ -0,0 +1,34 @@ +package distcache + +import ( + "bytes" + + "github.com/fluxninja/aperture/pkg/log" +) + +// OlricLogWriter is wrapper around aperture Logger that parse the message before writing to olricConfig.LogOutput. +type OlricLogWriter struct { + Logger log.Logger +} + +// Write writes the message and logs in aperture Logger format. +func (ol *OlricLogWriter) Write(message []byte) (int, error) { + message = bytes.TrimSpace(message) + if len(message) < 2 { + ol.Logger.Info().Msg(string(message)) + } else { + switch message[1] { + case 'I': + ol.Logger.Info().Msg(string(message[7:])) + case 'W': + ol.Logger.Warn().Msg(string(message[7:])) + case 'E': + ol.Logger.Error().Msg(string(message[8:])) + case 'D': + ol.Logger.Debug().Msg(string(message[8:])) + default: + ol.Logger.Info().Msg(string(message)) + } + } + return len(message), nil +} diff --git a/pkg/distcache/provider.go b/pkg/distcache/provider.go index e1dc047e17..c95eabce93 100644 --- a/pkg/distcache/provider.go +++ b/pkg/distcache/provider.go @@ -3,6 +3,7 @@ package distcache import ( "context" "errors" + stdlog "log" "net" "strconv" "sync" @@ -107,6 +108,7 @@ func (constructor DistCacheConstructor) ProvideDistCache(in DistCacheConstructor oc.ReadQuorum = 1 oc.MemberCountQuorum = 1 oc.DMaps.Custom = make(map[string]olricconfig.DMap) + oc.Logger = stdlog.New(&OlricLogWriter{Logger: log.GetGlobalLogger()}, "", 0) bindAddr, port, err := net.SplitHostPort(config.BindAddr) if err != nil { diff --git a/pkg/jobs/job-group.go b/pkg/jobs/job-group.go index 9760290f4f..b8c5e42d2f 100644 --- a/pkg/jobs/job-group.go +++ b/pkg/jobs/job-group.go @@ -3,7 +3,6 @@ package jobs import ( "context" "errors" - "fmt" "time" "github.com/go-co-op/gocron" @@ -176,8 +175,6 @@ func (jg *JobGroup) RegisterJob(job Job, config JobConfig) error { initialErr = errInitialResult } - fmt.Printf("\n\n registering job: %+v\n", job) - executor := newJobExecutor(job, jg, config) // add to the tracker err := jg.gt.registerJob(executor) diff --git a/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go b/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go index c61d7d90f2..4853e58f05 100644 --- a/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go +++ b/pkg/policies/dataplane/actuators/rate/ratetracker/rate-tracker_test.go @@ -3,6 +3,7 @@ package ratetracker import ( "context" "fmt" + stdlog "log" "math" "math/rand" "net" @@ -18,6 +19,7 @@ import ( "github.com/fluxninja/aperture/pkg/distcache" "github.com/fluxninja/aperture/pkg/jobs" + "github.com/fluxninja/aperture/pkg/log" "github.com/fluxninja/aperture/pkg/status" ) @@ -99,6 +101,7 @@ func newTestOlricConfig() *olricconfig.Config { mc.BindAddr = "127.0.0.1" mc.BindPort = 0 c.MemberlistConfig = mc + c.Logger = stdlog.New(&distcache.OlricLogWriter{Logger: log.GetGlobalLogger()}, "", 0) port, err := getFreePort() if err != nil {