sevlyar / go-daemon

A library for writing system daemons in golang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

daily log rotation (by midnight)

mSufi opened this issue · comments

commented

Hi sevlyar

I've tried the library and its work perfectly.

I just wondering. Did you have try to do go-daemon on daily log rotation (rotated at midnight)?

 func setupLog() {
        lf, err := NewLogFile(logFileName, os.Stderr)
	if err != nil {
		log.Fatal("Unable to create log file: ", err)
	}
	log.SetOutput(lf)
	// rotate log every 30 seconds.
	rotateLogSignal := time.Tick(30 * time.Second)
	go func() {
		for {
			<-rotateLogSignal
			if err := lf.Rotate(); err != nil {
				log.Fatal("Unable to rotate log: ", err)
			}
		}
	}()
}

Kindly advice.

@mSufi, i don't understand you. Could you explain exactly what issue do you have. Thank you.

commented

hi @sevlyar , sorry for the miscommunication.

Actually, I need to find a way to schedule the rotation of the daemon log for every day especially on midnight (12.00 AM).

I just wondering if you have tried to do so. Apparently, I already found the method (by using gocron).

Anyway, thanks for sharing this awesome library.

@mSufi I think gocron (or a simple own bicycle) will work fine in that case. Log rotation is not a target of the go-daemon library. I wrote the simple exsample of log rotation because there were too much questions about it.