Skip to content

Commit 980aa06

Browse files
committed
✅ test: add a test case for issues #137
1 parent ff670f2 commit 980aa06

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

issues_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/gookit/goutil/byteutil"
11+
"github.com/gookit/goutil/fsutil"
1112
"github.com/gookit/goutil/testutil/assert"
1213
"github.com/gookit/goutil/timex"
1314
"github.com/gookit/slog"
@@ -185,3 +186,23 @@ func TestIssues_121(t *testing.T) {
185186

186187
l.MustClose()
187188
}
189+
190+
// https://github.com/gookit/slog/issues/137
191+
// 按日期滚动 如果当天时间节点的日志文件已存在 不会append 会直接替换 #137
192+
func TestIssues_137(t *testing.T) {
193+
logFile := "testdata/issue137_case.log"
194+
fsutil.MustSave(logFile, "hello, this is a log file content\n")
195+
196+
l := slog.NewWithHandlers(handler.MustFileHandler(logFile))
197+
198+
// add logs
199+
for i := 0; i < 5; i++ {
200+
l.Infof("hi, this is a example information ... message text. log index=%d", i)
201+
}
202+
203+
l.MustClose()
204+
// read file content
205+
content := fsutil.ReadString(logFile)
206+
assert.StrContains(t, content, "this is a log file content")
207+
assert.StrContains(t, content, "log index=4")
208+
}

0 commit comments

Comments
 (0)