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 {

View file

@ -1,16 +1,19 @@
package accesslog
import (
"time"
"github.com/yusing/go-proxy/internal/gperr"
"github.com/yusing/go-proxy/internal/utils"
)
type (
ConfigBase struct {
BufferSize int `json:"buffer_size"`
Path string `json:"path"`
Stdout bool `json:"stdout"`
Retention *Retention `json:"retention" aliases:"keep"`
BufferSize int `json:"buffer_size"`
Path string `json:"path"`
Stdout bool `json:"stdout"`
Retention *Retention `json:"retention" aliases:"keep"`
RotateInterval time.Duration `json:"rotate_interval,omitempty"`
}
ACLLoggerConfig struct {
ConfigBase