feat: tunable rotate interval

This commit is contained in:
yusing
2025-04-30 18:19:00 +08:00
parent 53d54a09b0
commit 829eb08e37
2 changed files with 13 additions and 7 deletions

View File

@@ -66,8 +66,8 @@ const (
)
const (
flushInterval = 30 * time.Second
rotateInterval = time.Hour
flushInterval = 30 * time.Second
defaultRotateInterval = time.Hour
)
const (
@@ -117,6 +117,9 @@ func NewAccessLoggerWithIO(parent task.Parent, writer WriterWithName, anyCfg Any
if _, ok := writer.(*os.File); ok {
cfg.BufferSize = StdoutbufSize
}
if cfg.RotateInterval == 0 {
cfg.RotateInterval = defaultRotateInterval
}
l := &AccessLogger{
task: parent.Subtask("accesslog."+writer.Name(), true),
@@ -238,7 +241,7 @@ func (l *AccessLogger) start() {
flushTicker := time.NewTicker(30 * time.Second)
defer flushTicker.Stop()
rotateTicker := time.NewTicker(rotateInterval)
rotateTicker := time.NewTicker(l.cfg.RotateInterval)
defer rotateTicker.Stop()
for {