diff --git a/log/formatter/general.go b/log/formatter/general.go index 86e51635f..292c03eb8 100644 --- a/log/formatter/general.go +++ b/log/formatter/general.go @@ -11,6 +11,7 @@ import ( "github.com/goravel/framework/contracts/config" "github.com/goravel/framework/contracts/foundation" + "github.com/goravel/framework/support/str" ) type General struct { @@ -82,9 +83,9 @@ func (general *General) formatData(data logrus.Fields) (string, error) { return "", err } - for _, key := range []string{"code", "context", "with", "domain", "hint", "owner", "request", "response", "tags", "user"} { + 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", key, value)) + builder.WriteString(fmt.Sprintf("%s: %+v\n", str.Of(key).UcFirst().String(), value)) } } @@ -113,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 23fc5d5d0..2e5367d9c 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 860d4a08e..6d5020b9e 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\nContext: map[key:value]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nContext: 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\nCode: code")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nCode: 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\nHint: hint")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nHint: 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\nDomain: domain")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nDomain: 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\nOwner: team@goravel.dev")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nOwner: team@goravel.dev")) }, }, { @@ -272,7 +272,7 @@ func TestLogrus(t *testing.T) { assert: func() { expectedParts := []string{ `test.info: Goravel`, - `request: `, + `Request: `, `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\nTags: [tag]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nTags: [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\nUser: map[name:kkumar-gcc]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nUser: 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\nWith: map[key:value]")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nWith: 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\nTrace:")) + assert.True(t, file.Contain(dailyLog, "test.info: Goravel\nTrace:")) }, }, { @@ -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\nTrace:")) 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\nTrace:")) 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\nTrace:")) }, }, }