github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/zlog/config_test.go (about)

     1  package zlog
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"go.uber.org/zap/zapcore"
     8  )
     9  
    10  func TestNew(t *testing.T) {
    11  	logger, props, err := New(&Config{Level: "trace", Format: "logfmt"})
    12  	require.Nil(t, err)
    13  	require.NotNil(t, logger)
    14  	require.NotNil(t, props)
    15  	defer props.CloseWriters()
    16  
    17  	Logger{Logger: logger}.Trace("trace message")
    18  	logger.Info("info message")
    19  }
    20  
    21  func TestNewWithCore(t *testing.T) {
    22  	cfg := &WrapCoreConfig{
    23  		Level: TraceLevel,
    24  	}
    25  	core := zapcore.NewNopCore()
    26  	logger, props, err := NewWithCore(cfg, core)
    27  	require.Nil(t, err)
    28  	require.NotNil(t, logger)
    29  	require.NotNil(t, props)
    30  	defer props.CloseWriters()
    31  
    32  	Logger{Logger: logger}.Trace("trace message")
    33  	logger.Info("info message")
    34  }