mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
feat: tunable rotate interval
This commit is contained in:
parent
53d54a09b0
commit
829eb08e37
2 changed files with 13 additions and 7 deletions
|
@ -67,7 +67,7 @@ const (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flushInterval = 30 * time.Second
|
flushInterval = 30 * time.Second
|
||||||
rotateInterval = time.Hour
|
defaultRotateInterval = time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -117,6 +117,9 @@ func NewAccessLoggerWithIO(parent task.Parent, writer WriterWithName, anyCfg Any
|
||||||
if _, ok := writer.(*os.File); ok {
|
if _, ok := writer.(*os.File); ok {
|
||||||
cfg.BufferSize = StdoutbufSize
|
cfg.BufferSize = StdoutbufSize
|
||||||
}
|
}
|
||||||
|
if cfg.RotateInterval == 0 {
|
||||||
|
cfg.RotateInterval = defaultRotateInterval
|
||||||
|
}
|
||||||
|
|
||||||
l := &AccessLogger{
|
l := &AccessLogger{
|
||||||
task: parent.Subtask("accesslog."+writer.Name(), true),
|
task: parent.Subtask("accesslog."+writer.Name(), true),
|
||||||
|
@ -238,7 +241,7 @@ func (l *AccessLogger) start() {
|
||||||
flushTicker := time.NewTicker(30 * time.Second)
|
flushTicker := time.NewTicker(30 * time.Second)
|
||||||
defer flushTicker.Stop()
|
defer flushTicker.Stop()
|
||||||
|
|
||||||
rotateTicker := time.NewTicker(rotateInterval)
|
rotateTicker := time.NewTicker(l.cfg.RotateInterval)
|
||||||
defer rotateTicker.Stop()
|
defer rotateTicker.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package accesslog
|
package accesslog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/yusing/go-proxy/internal/gperr"
|
"github.com/yusing/go-proxy/internal/gperr"
|
||||||
"github.com/yusing/go-proxy/internal/utils"
|
"github.com/yusing/go-proxy/internal/utils"
|
||||||
)
|
)
|
||||||
|
@ -11,6 +13,7 @@ type (
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
Stdout bool `json:"stdout"`
|
Stdout bool `json:"stdout"`
|
||||||
Retention *Retention `json:"retention" aliases:"keep"`
|
Retention *Retention `json:"retention" aliases:"keep"`
|
||||||
|
RotateInterval time.Duration `json:"rotate_interval,omitempty"`
|
||||||
}
|
}
|
||||||
ACLLoggerConfig struct {
|
ACLLoggerConfig struct {
|
||||||
ConfigBase
|
ConfigBase
|
||||||
|
|
Loading…
Add table
Reference in a new issue