diff --git a/internal/logging/accesslog/access_logger.go b/internal/logging/accesslog/access_logger.go index 14f2f55..d6ec4a7 100644 --- a/internal/logging/accesslog/access_logger.go +++ b/internal/logging/accesslog/access_logger.go @@ -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 { diff --git a/internal/logging/accesslog/config.go b/internal/logging/accesslog/config.go index 7395213..82aa381 100644 --- a/internal/logging/accesslog/config.go +++ b/internal/logging/accesslog/config.go @@ -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