func (l *AuditLog) rotateLog() (err error) {
	// determine the timestamp for the current log file
	fileTime := l.TimeSource().In(time.UTC).Round(l.RotationPeriod)

	openLogFile := func() error {
		l.Lock()
		defer l.Unlock()
		logfname := filepath.Join(l.dataDir,
			fileTime.Format("2006-01-02.15:04:05")+LogfileExt)
		l.file, err = os.OpenFile(logfname, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
		if err != nil {
			log.Error(err)
		}
		l.fileTime = fileTime
		return trace.Wrap(err)
	}

	// need to create a log file?
	if l.file == nil {
		return openLogFile()
	}

	// time to advance the logfile?
	if l.fileTime.Before(fileTime) {
		l.file.Close()
		return openLogFile()
	}
	return nil
}
// rotateLog() checks if the current log file is older than a given duration,
// and if it is, closes it and opens a new one
rotateLog() checks if the current log file is older than a given duration,
and if it is, closes it and opens a new one
// rotateLog () checks if the current log file is older than a given duration // and if it is closes it and opens a new one
func (l *AuditLog) rotateLog() (err error) {
	fileTime := l.TimeSource().In(time.UTC).Round(l.RotationPeriod)
	openLogFile := func() error {
		l.Lock()
		defer l.Unlock()
		logfname := filepath.Join(l.dataDir,
			fileTime.Format("2006-01-02.15:04:05")+LogfileExt)
		l.file, err = os.OpenFile(logfname, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
		if err != nil {
			log.Error(err)
		}
		l.fileTime = fileTime
		return trace.Wrap(err)
	}
	if l.file == nil {
		return openLogFile()
	}
	if l.fileTime.Before(fileTime) {
		l.file.Close()
		return openLogFile()
	}
	return nil
}
func ( l * AuditLog ) rotateLog ( ) ( err error ) { fileTime := l . TimeSource ( ) . In ( time . UTC ) . Round ( l . RotationPeriod ) openLogFile := func ( ) error { l . Lock ( ) defer l . Unlock ( ) logfname := filepath . Join ( l . dataDir , fileTime . Format ( " " ) + LogfileExt ) l . file , err = os . OpenFile ( logfname , os . O_WRONLY | os . O_CREATE | os . O_APPEND , 0640 ) if err != nil { log . Error ( err ) } l . fileTime = fileTime return trace . Wrap ( err ) } if l . file == nil { return openLogFile ( ) } if l . fileTime . Before ( fileTime ) { l . file . Close ( ) return openLogFile ( ) } return nil }
rotateLog() checks if the current log file is older than a given duration,
and if it is, closes it and opens a new one
rotateLog () checks if the current log file is older than a given duration and if it is closes it and opens a new one
// determine the timestamp for the current log file // need to create a log file? // time to advance the logfile?