pkg/logutil: add "NewRaftLoggerFromZapCore"
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
@ -20,10 +20,12 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
)
|
||||
|
||||
func TestNewRaftLogger(t *testing.T) {
|
||||
@ -68,3 +70,20 @@ func TestNewRaftLogger(t *testing.T) {
|
||||
t.Fatalf("unexpected caller; %q", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewRaftLoggerFromZapCore(t *testing.T) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
syncer := zapcore.AddSync(buf)
|
||||
cr := zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
|
||||
syncer,
|
||||
zap.NewAtomicLevelAt(zap.InfoLevel),
|
||||
)
|
||||
|
||||
lg := NewRaftLoggerFromZapCore(cr, syncer)
|
||||
lg.Info("TestNewRaftLoggerFromZapCore")
|
||||
txt := buf.String()
|
||||
if !strings.Contains(txt, "TestNewRaftLoggerFromZapCore") {
|
||||
t.Fatalf("unexpected log %q", txt)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user