lni / dragonboat

A feature complete and high performance multi-group Raft library in Go.
Apache License 2.0
5.08k stars 541 forks source link

Logger factory does not handle gossip logs #198

Closed lebovski closed 2 years ago

lebovski commented 3 years ago

In order to transfer my logger to dragonboat I use logger.SetLoggerFactory, but the gossip service keeps writing logs to stdout.

Dragonboat version

v3.3.4

Expected behavior

Logs from gossip written to my logger.

Actual behavior

Logs from gossip written to stdout.

Steps to reproduce the behavior

Simple example of wrapper code:

package dragonboat

import (
    "sync"

    "github.com/lni/dragonboat/v3/logger"
)

var (
    onceLogger sync.Once
)

var _ logger.ILogger = (*loggerWrap)(nil)

type loggerWrap struct{}

func (l *loggerWrap) SetLevel(_ logger.LogLevel) {
    // custom logger code
}

func (l *loggerWrap) Debugf(_ string, _ ...interface{}) {
    // custom logger code
}

func (l *loggerWrap) Infof(_ string, _ ...interface{}) {
    // custom logger code
}

func (l *loggerWrap) Warningf(_ string, _ ...interface{}) {
    // custom logger code
}

func (l *loggerWrap) Errorf(_ string, _ ...interface{}) {
    // custom logger code
}

func (l *loggerWrap) Panicf(_ string, _ ...interface{}) {
    // custom logger code
}

func initLogger() {
    onceLogger.Do(func() {
        logger.SetLoggerFactory(func(_ string) logger.ILogger { return &loggerWrap{} })
    })
}

In this example all logs is ignored, but gossip write logs to stdout.

lni commented 3 years ago

@lebovski you need to add some code for dragonboat to plumb memberlist's (the gossip library used in dragonboat) logging to the logger used by dragonboat.

you can write a logger wrapper for memberlist and specify it here - https://github.com/hashicorp/memberlist/blob/619135cdd9e5dda8c12f8ceef39bdade4f5899b6/config.go#L212

this logger should just pass all logging info to your above loggerWrap used in dragonboat.

Any chance you can help to look into the problem and send a PR? Will really appreciate that.

lebovski commented 3 years ago

I prepared pr, please review: https://github.com/lni/dragonboat/pull/217

lni commented 2 years ago

already resolved #217