Skip to content

Commit

Permalink
Add wrapper around olric log (#289)
Browse files Browse the repository at this point in the history
* Add wrapper around olric logger

* Remove remaining print
  • Loading branch information
seunghyupoh3517 authored and slayer321 committed Sep 1, 2022
1 parent 3e5792b commit 19b8abc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
34 changes: 34 additions & 0 deletions pkg/distcache/olric-logwriter.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions pkg/distcache/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package distcache
import (
"context"
"errors"
stdlog "log"
"net"
"strconv"
"sync"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions pkg/jobs/job-group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package jobs
import (
"context"
"errors"
"fmt"
"time"

"github.com/go-co-op/gocron"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ratetracker
import (
"context"
"fmt"
stdlog "log"
"math"
"math/rand"
"net"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 19b8abc

Please sign in to comment.