Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add fields with logx methods, support using third party logging…
… libs. (#1847) * backup * simplify * chore: remove unused pool * chore: fix lint errors * chore: use strings.Builder instead of bytes.Buffer * test: add more tests * chore: fix reviewdog * test: fix data race * feat: make logger customizable * chore: fix reviewdog * test: fix fails * chore: fix set writer twice * chore: use context instead of golang.org context * chore: specify uint32 for level types
- Loading branch information
Showing
21 changed files
with
1,550 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
package logx | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLessLogger_Error(t *testing.T) { | ||
var builder strings.Builder | ||
log.SetOutput(&builder) | ||
w := new(mockWriter) | ||
old := writer.Swap(w) | ||
defer writer.Store(old) | ||
|
||
l := NewLessLogger(500) | ||
for i := 0; i < 100; i++ { | ||
l.Error("hello") | ||
} | ||
|
||
assert.Equal(t, 1, strings.Count(builder.String(), "\n")) | ||
assert.Equal(t, 1, strings.Count(w.String(), "\n")) | ||
} | ||
|
||
func TestLessLogger_Errorf(t *testing.T) { | ||
var builder strings.Builder | ||
log.SetOutput(&builder) | ||
w := new(mockWriter) | ||
old := writer.Swap(w) | ||
defer writer.Store(old) | ||
|
||
l := NewLessLogger(500) | ||
for i := 0; i < 100; i++ { | ||
l.Errorf("hello") | ||
} | ||
|
||
assert.Equal(t, 1, strings.Count(builder.String(), "\n")) | ||
assert.Equal(t, 1, strings.Count(w.String(), "\n")) | ||
} |
Oops, something went wrong.