From 38247cf3c9e573e481078a8bf985b5de94753a80 Mon Sep 17 00:00:00 2001 From: yuxh Date: Fri, 28 Oct 2022 17:18:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Des=20type=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log_test.go | 18 ++++++++++++++++++ logs/es/es.go | 2 +- logs/file_test.go | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/log_test.go b/log_test.go index 350a9ab..b05fded 100644 --- a/log_test.go +++ b/log_test.go @@ -78,3 +78,21 @@ func TestNew(t *testing.T) { wg.Wait() } + +func TestGetEs(t *testing.T) { + wg := sync.WaitGroup{} + for i := 0; i < 10; i++ { + wg.Add(1) + go func(i int) { + GetEs("ok").Debug("%d", i) + time.Sleep(time.Second * 10) + wg.Done() + }(i) + } + + for i := 0; i < 10; i++ { + GetEs("ok").Debug("aaaaaa%d", i) + } + + wg.Wait() +} diff --git a/logs/es/es.go b/logs/es/es.go index d017282..abcc255 100644 --- a/logs/es/es.go +++ b/logs/es/es.go @@ -89,7 +89,7 @@ func (el *esLogger) WriteMsg(when time.Time, msg string, level int, lable string d := goes.Document{ Index: fmt.Sprintf("%s-%04d.%02d.%02d", el.IndexName, when.Year(), when.Month(), when.Day()), - Type: "logs", + Type: "_doc", Fields: vals, } _, err := el.Index(d, nil) diff --git a/logs/file_test.go b/logs/file_test.go index 385eac4..dd02f91 100644 --- a/logs/file_test.go +++ b/logs/file_test.go @@ -281,7 +281,7 @@ func testFileRotate(t *testing.T, fn1, fn2 string, daily, hourly bool) { fw.hourlyOpenDate = fw.hourlyOpenTime.Day() } - fw.WriteMsg(time.Now(), "this is a msg for test", LevelDebug) + fw.WriteMsg(time.Now(), "this is a msg for test", LevelDebug, "", "dev") for _, file := range []string{fn1, fn2} { _, err := os.Stat(file)