Skip to content

Commit

Permalink
chore: replace : with [] (#791)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl authored Dec 26, 2024
1 parent 50da8bd commit 38c26f0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions log/formatter/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down Expand Up @@ -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 {
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\n[Context] map[key:value]"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Context] 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\n[Code] code"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Code] 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\n[Hint] hint"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Hint] 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\n[Domain] domain"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Domain] 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\n[Owner] team@goravel.dev"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Owner] team@goravel.dev"))
},
},
{
Expand All @@ -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]`,
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\n[Tags] [tag]"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Tags] [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\n[User] map[name:kkumar-gcc]"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[User] 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\n[With] map[key:value]"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[With] 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\n[Trace]"))
assert.True(t, file.Contain(dailyLog, "test.info: Goravel\n[Trace]"))
},
},
{
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\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]"))
},
},
}
Expand Down

0 comments on commit 38c26f0

Please sign in to comment.