From 629f4a5fa6fd86bc6b724ca09a5e94053a833443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Tue, 17 Mar 2026 16:53:09 +0200 Subject: [PATCH] added simple log rotator --- app/config/config.go | 2 ++ app/server/server.go | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/config/config.go b/app/config/config.go index 8a3adf6..00f0eb7 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -48,6 +48,7 @@ type Config struct { Datadir string `json:"datadir" yaml:datadir` Hostname string `json:"hostname" yaml:hostname` Hostnames []string `json:"hostnames" yaml:hostnames` + LogLimit int64 `json:"logLimit" yaml:logLimit` } func NewConfig() *Config { @@ -82,6 +83,7 @@ func NewConfig() *Config { //Certpath: certpath, //Keypath: keypath, Hostnames: make([]string, 0), + LogLimit: 1024 * 1024 * 10, // 10 Mb } } diff --git a/app/server/server.go b/app/server/server.go index 1f54560..028a302 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -431,6 +431,24 @@ func (srv *Server) Daemonize() error { if err != nil { return err } + // Log file rotator + logFunc := func() { + for { + stat, err := os.Stat(srv.conf.Logpath) + if err == nil && stat.Size() > srv.conf.LogLimit { + os.Rename(srv.conf.Logpath+".2", srv.conf.Logpath+".3") + os.Rename(srv.conf.Logpath+".1", srv.conf.Logpath+".2") + os.Rename(srv.conf.Logpath, srv.conf.Logpath+".1") + logFile.Close() + logFile, err = os.OpenFile(srv.conf.Logpath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640) + syscall.Dup2(int(logFile.Fd()), int(os.Stdout.Fd())) + syscall.Dup2(int(logFile.Fd()), int(os.Stderr.Fd())) + time.Sleep(10 * time.Second) + } + + } + } + go logFunc() // Write process ID rundir := filepath.Dir(srv.conf.Runpath) err = os.MkdirAll(rundir, 0750)