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)