mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: add test for logging rotate size (#3587)
This commit is contained in:
parent
814852f0b8
commit
4222fd97bc
@ -298,6 +298,7 @@ func (l *RotateLogger) initialize() error {
|
|||||||
if l.fp, err = os.OpenFile(l.filename, os.O_APPEND|os.O_WRONLY, defaultFileMode); err != nil {
|
if l.fp, err = os.OpenFile(l.filename, os.O_APPEND|os.O_WRONLY, defaultFileMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
l.currentSize = fileInfo.Size()
|
l.currentSize = fileInfo.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,6 +517,21 @@ func TestGzipFile(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRotateLogger_WithExistingFile(t *testing.T) {
|
||||||
|
const body = "foo"
|
||||||
|
filename, err := fs.TempFilenameWithText(body)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
if len(filename) > 0 {
|
||||||
|
defer os.Remove(filename)
|
||||||
|
}
|
||||||
|
|
||||||
|
rule := NewSizeLimitRotateRule(filename, "-", 1, 100, 3, false)
|
||||||
|
logger, err := NewLogger(filename, rule, false)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, int64(len(body)), logger.currentSize)
|
||||||
|
assert.Nil(t, logger.Close())
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkRotateLogger(b *testing.B) {
|
func BenchmarkRotateLogger(b *testing.B) {
|
||||||
filename := "./test.log"
|
filename := "./test.log"
|
||||||
filename2 := "./test2.log"
|
filename2 := "./test2.log"
|
||||||
|
Loading…
Reference in New Issue
Block a user