pkg/logutil: add "NewGRPCLoggerV2FromZapCore"

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
Gyuho Lee
2018-04-24 15:23:40 -07:00
parent fcbb30364a
commit 1fa80bf520
2 changed files with 28 additions and 0 deletions

View File

@ -20,10 +20,12 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
func TestNewGRPCLoggerV2(t *testing.T) {
@ -70,3 +72,20 @@ func TestNewGRPCLoggerV2(t *testing.T) {
t.Fatalf("unexpected caller; %q", string(data))
}
}
func TestNewGRPCLoggerV2FromZapCore(t *testing.T) {
buf := bytes.NewBuffer(nil)
syncer := zapcore.AddSync(buf)
cr := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
syncer,
zap.NewAtomicLevelAt(zap.InfoLevel),
)
lg := NewGRPCLoggerV2FromZapCore(cr, syncer)
lg.Warning("TestNewGRPCLoggerV2FromZapCore")
txt := buf.String()
if !strings.Contains(txt, "TestNewGRPCLoggerV2FromZapCore") {
t.Fatalf("unexpected log %q", txt)
}
}