From 8e676c2f711dad27412dce395628b5cf65641ece Mon Sep 17 00:00:00 2001 From: Bowen Date: Wed, 25 Dec 2024 17:33:37 +0800 Subject: [PATCH] chore: replace : with [] --- log/formatter/general.go | 4 +-- log/formatter/general_test.go | 20 +++++++-------- log/logrus_writer_test.go | 46 +++++++++++++++++------------------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/log/formatter/general.go b/log/formatter/general.go index 292c03eb8..e175ba590 100644 --- a/log/formatter/general.go +++ b/log/formatter/general.go @@ -85,7 +85,7 @@ func (general *General) formatData(data logrus.Fields) (string, error) { for _, key := range []string{"hint", "tags", "owner", "context", "with", "domain", "code", "request", "response", "user"} { if value, exists := root[key]; exists && value != nil { - builder.WriteString(fmt.Sprintf("%s: %+v\n", str.Of(key).UcFirst().String(), value)) + builder.WriteString(fmt.Sprintf("[%s] %+v\n", str.Of(key).UcFirst().String(), value)) } } @@ -114,7 +114,7 @@ func (general *General) formatStackTraces(stackTraces any) (string, error) { if err != nil { return "", err } - formattedTraces.WriteString("Trace:\n") + formattedTraces.WriteString("[Trace]\n") root := traces.Root if len(root.Stack) > 0 { for _, stackStr := range root.Stack { diff --git a/log/formatter/general_test.go b/log/formatter/general_test.go index 2e5367d9c..981286497 100644 --- a/log/formatter/general_test.go +++ b/log/formatter/general_test.go @@ -71,10 +71,10 @@ func (s *GeneralTestSuite) TestFormat() { assert: func() { formatLog, err := general.Format(s.entry) s.Nil(err) - s.Contains(string(formatLog), "Code: 200") - s.Contains(string(formatLog), "Domain: example.com") - s.Contains(string(formatLog), "Owner: owner") - s.Contains(string(formatLog), "User: user1") + s.Contains(string(formatLog), "[Code] 200") + s.Contains(string(formatLog), "[Domain] example.com") + s.Contains(string(formatLog), "[Owner] owner") + s.Contains(string(formatLog), "[User] user1") }, }, } @@ -135,10 +135,10 @@ func (s *GeneralTestSuite) TestFormatData() { assert: func() { formattedData, err := general.formatData(data) s.Nil(err) - s.Contains(formattedData, "Code: 200") - s.Contains(formattedData, "Domain: example.com") - s.Contains(formattedData, "Owner: owner") - s.Contains(formattedData, "User: user1") + s.Contains(formattedData, "[Code] 200") + s.Contains(formattedData, "[Domain] example.com") + s.Contains(formattedData, "[Owner] owner") + s.Contains(formattedData, "[User] user1") }, }, } @@ -167,7 +167,7 @@ func (s *GeneralTestSuite) TestFormatStackTraces() { assert: func() { traces, err := general.formatStackTraces(stackTraces) s.Nil(err) - s.Equal("Trace:\n", traces) + s.Equal("[Trace]\n", traces) }, }, { @@ -200,7 +200,7 @@ func (s *GeneralTestSuite) TestFormatStackTraces() { "/dummy/examples/logging/example.go:29 [main.(*Request).Validate]", "/dummy/examples/logging/example.go:28 [main.(*Request).Validate]", } - formattedStackTraces := "Trace:\n" + strings.Join(stackTraces, "\n") + "\n" + formattedStackTraces := "[Trace]\n" + strings.Join(stackTraces, "\n") + "\n" s.Equal(formattedStackTraces, traces) }, diff --git a/log/logrus_writer_test.go b/log/logrus_writer_test.go index 6d5020b9e..7974152d9 100644 --- a/log/logrus_writer_test.go +++ b/log/logrus_writer_test.go @@ -58,8 +58,8 @@ func TestLogrus(t *testing.T) { log.WithContext(ctx).Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nContext: map[key:value]")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nContext: map[key:value]")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Context] map[key:value]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Context] map[key:value]")) }, }, { @@ -218,8 +218,8 @@ func TestLogrus(t *testing.T) { log.Code("code").Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nCode: code")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nCode: code")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Code] code")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Code] code")) }, }, { @@ -231,8 +231,8 @@ func TestLogrus(t *testing.T) { log.Hint("hint").Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nHint: hint")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nHint: hint")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Hint] hint")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Hint] hint")) }, }, { @@ -244,8 +244,8 @@ func TestLogrus(t *testing.T) { log.In("domain").Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nDomain: domain")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nDomain: domain")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Domain] domain")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Domain] domain")) }, }, { @@ -257,8 +257,8 @@ func TestLogrus(t *testing.T) { log.Owner("team@goravel.dev").Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nOwner: team@goravel.dev")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nOwner: team@goravel.dev")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Owner] team@goravel.dev")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Owner] team@goravel.dev")) }, }, { @@ -272,7 +272,7 @@ func TestLogrus(t *testing.T) { assert: func() { expectedParts := []string{ `test.info: Goravel`, - `Request: `, + `[Request] map[`, `method:GET`, `uri:http://localhost:3000/`, `Sec-Fetch-User:[?1]`, @@ -297,7 +297,7 @@ func TestLogrus(t *testing.T) { assert: func() { expectedParts := []string{ `test.info: Goravel`, - `Response: map[`, + `[Response] map[`, `status:200`, `header:map[Content-Type:[text/plain; charset=utf-8]]`, `body:body`, @@ -319,8 +319,8 @@ func TestLogrus(t *testing.T) { log.Tags("tag").Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nTags: [tag]")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nTags: [tag]")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Tags] [tag]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Tags] [tag]")) }, }, { @@ -332,8 +332,8 @@ func TestLogrus(t *testing.T) { log.User(map[string]any{"name": "kkumar-gcc"}).Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nUser: map[name:kkumar-gcc]")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nUser: map[name:kkumar-gcc]")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[User] map[name:kkumar-gcc]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[User] map[name:kkumar-gcc]")) }, }, { @@ -345,8 +345,8 @@ func TestLogrus(t *testing.T) { log.With(map[string]any{"key": "value"}).Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nWith: map[key:value]")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nWith: map[key:value]")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[With] map[key:value]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[With] map[key:value]")) }, }, { @@ -358,8 +358,8 @@ func TestLogrus(t *testing.T) { log.WithTrace().Info("Goravel") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.info: Goravel\nTrace:")) - assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nTrace:")) + assert.True(t, file.Contain(singleLog, "test.info: Goravel\n[Trace]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Trace]")) }, }, { @@ -372,12 +372,12 @@ func TestLogrus(t *testing.T) { log.Info("test info") }, assert: func() { - assert.True(t, file.Contain(singleLog, "test.error: test error\nTrace:")) + assert.True(t, file.Contain(singleLog, "test.error: test error\n[Trace]")) assert.True(t, file.Contain(singleLog, "test.info: test info")) - assert.False(t, file.Contain(dailyLog, "test.info: test info\nTrace:")) + assert.False(t, file.Contain(dailyLog, "test.info: test info\n[Trace]")) assert.True(t, file.Contain(dailyLog, "test.error: test error")) assert.True(t, file.Contain(dailyLog, "test.info: test info")) - assert.False(t, file.Contain(singleLog, "test.info: test info\nTrace:")) + assert.False(t, file.Contain(singleLog, "test.info: test info\n[Trace]")) }, }, }