vmware-go-kcl-v2/logger/zap/zap_test.go
Tao Jiang 86cc5a1a64 Update the libray reference path to new repo
Signed-off-by: Tao Jiang <taoj@vmware.com>
2021-12-21 13:49:47 -06:00

39 lines
976 B
Go

package zap_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/vmware/vmware-go-kcl-v2/logger"
"github.com/vmware/vmware-go-kcl-v2/logger/zap"
uzap "go.uber.org/zap"
)
func TestZapLoggerWithConfig(t *testing.T) {
config := logger.Configuration{
EnableConsole: true,
ConsoleLevel: logger.Debug,
ConsoleJSONFormat: true,
EnableFile: false,
FileLevel: logger.Info,
FileJSONFormat: true,
Filename: "log.log",
}
log := zap.NewZapLoggerWithConfig(config)
contextLogger := log.WithFields(logger.Fields{"key1": "value1"})
contextLogger.Debugf("Starting with zap")
contextLogger.Infof("Zap is awesome")
}
func TestZapLogger(t *testing.T) {
zapLogger, err := uzap.NewProduction()
assert.Nil(t, err)
log := zap.NewZapLogger(zapLogger.Sugar())
contextLogger := log.WithFields(logger.Fields{"key1": "value1"})
contextLogger.Debugf("Starting with zap")
contextLogger.Infof("Zap is awesome")
}