added simple log rotator

This commit is contained in:
2026-03-17 16:53:09 +02:00
parent 52789ef4d1
commit 629f4a5fa6
2 changed files with 20 additions and 0 deletions
+18
View File
@@ -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)