package logger

import (
	"testing"

	"bindbox-game/internal/pkg/timeutil"

	"github.com/pkg/errors"
	"go.uber.org/zap"
)

func TestJSONLogger(t *testing.T) {
	logger, err := NewJSONLogger(
		WithField("defined_key", "defined_value"),
		WithTimeLayout(timeutil.CSTLayout),
		WithOutputInConsole(),
	)
	if err != nil {
		t.Fatal(err)
	}
	defer logger.Sync()

	err = errors.New("pkg error")
	logger.Error("err occurs", WrapMeta(nil, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
	logger.Error("err occurs", WrapMeta(err, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)

}

func TestCustomLogger(t *testing.T) {
	logger, err := NewCustomLogger(nil,
		WithField("defined_key", "defined_value"),
		WithTimeLayout(timeutil.CSTLayout),
		//WithOutputInConsole(),

	)

	if err != nil {
		t.Fatal(err)
	}
	defer logger.Sync()

	err = errors.New("pkg error")
	logger.Info("none err")
	logger.Info("with err", zap.Error(err))
	logger.Info("err occurs", WrapMeta(nil, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
	logger.Info("err occurs", WrapMeta(err, NewMeta("para1", "value1"), NewMeta("para2", "value2"))...)
}

func BenchmarkJsonLogger(b *testing.B) {
	b.ResetTimer()
	logger, err := NewJSONLogger(
		WithField("defined_key", "defined_value"),
	)
	if err != nil {
		b.Fatal(err)
	}

	defer logger.Sync()

}
