Skip to content

Commit

Permalink
optimize first letter
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl committed Dec 15, 2024
1 parent 806a811 commit 05846b7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
7 changes: 4 additions & 3 deletions log/formatter/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 10 additions & 10 deletions log/formatter/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
},
}
Expand Down Expand Up @@ -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")
},
},
}
Expand Down Expand Up @@ -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)
},
},
{
Expand Down Expand Up @@ -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)
},
Expand Down
46 changes: 23 additions & 23 deletions log/logrus_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]"))
},
},
{
Expand Down Expand Up @@ -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"))
},
},
{
Expand All @@ -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"))
},
},
{
Expand All @@ -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"))
},
},
{
Expand All @@ -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"))
},
},
{
Expand All @@ -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]`,
Expand All @@ -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`,
Expand All @@ -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]"))
},
},
{
Expand All @@ -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]"))
},
},
{
Expand All @@ -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]"))
},
},
{
Expand All @@ -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:"))
},
},
{
Expand All @@ -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:"))
},
},
}
Expand Down

0 comments on commit 05846b7

Please sign in to comment.