package zaptg_test import ( "context" "github.com/BlackBroker/trashlog/wrappers/zaptg" . "github.com/onsi/ginkgo" "github.com/themakers/hlog" "go.uber.org/zap" "go.uber.org/zap/zapcore" "fmt" ) var _ = Describe("Zaptg", func() { logger, err := zap.NewProduction() if err != nil { panic(err) } logger = logger.Named("test") ctx := context.Background() tl, err := zaptg.NewCore( ctx, zap.InfoLevel, "1408111289:AAHfWZRiBQRncb2gl2LtU8OeASjfJi4e8YE", "v0", "test", 0, -1001230000451, ) if err != nil { panic(err) } logger = logger.WithOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core { return zapcore.NewTee(core, tl) })) log := hlog.New(logger).Module("test1") Context("Main", func() { It("LogSomeData", func() { log.Emit(InfoTest{Test: "test"}) }) It("check different named", func() { log1 := log.Module("testDifferentLoggers1") log2 := log.Module("testDifferentLoggers2") log1.Emit(InfoTest{Test: "test"}) log2.Emit(InfoTest{Test: "test"}) log1.Emit(InfoTest{Test: "test"}) }) It("check different with", func(){ log1 := log.With(map[string]string{ "test1": "aaa", }) log1.Emit(InfoTest{Test: "test"}) log1 = log.With(map[string]string{ "test2":"bbb", }) log1.Emit(InfoTest{Test: "test"}) log2 := log.With(map[string]string{ "test1": "ccc", }) log2.Emit(InfoTest{Test: "test"}) log2 = log1.With(map[string]string{ "test3":"ddd", }) log2.Emit(InfoTest{Test: "test"}) }) It("check with race", func() { ch := make(chan int, 2) log1 := log.Module("WithRace") cctx, cancel := context.WithCancel(ctx) defer cancel() bench := func() { for { select { case i := <-ch: log1.With(map[string]int{ fmt.Sprintf("test%d",i): i, }) case <-cctx.Done(): return } } } for i := 0; i< 5;i++ { go bench() } for i := 0; i< 100;i++ { ch <- i } log1.Emit(InfoTest{Test: "test"}) }) }) }) type InfoTest struct { Test string }