code: func (l *FileLog) rotateLog() (err error) {
  	l.Lock()
  	defer l.Unlock()
  
  	// determine the timestamp for the current log file
  	fileTime := l.Clock.Now().In(time.UTC)
  
  	// truncate time to the resolution of one day, cutting at the day end boundary
  	fileTime = time.Date(fileTime.Year(), fileTime.Month(), fileTime.Day(), 0, 0, 0, 0, time.UTC)
  
  	logFilename := filepath.Join(l.Dir,
  		fileTime.Format(defaults.AuditLogTimeFormat)+LogfileExt)
  
  	openLogFile := func() error {
  		l.file, err = os.OpenFile(logFilename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
  		if err != nil {
  			log.Error(err)
  		}
  		l.fileTime = fileTime
  		return trace.Wrap(err)
  	}
  
  	linkFilename := filepath.Join(l.SymlinkDir, SymlinkFilename)
  	createSymlink := func() error {
  		err = trace.ConvertSystemError(os.Remove(linkFilename))
  		if err != nil {
  			if !trace.IsNotFound(err) {
  				return trace.Wrap(err)
  			}
  		}
  		return trace.ConvertSystemError(os.Symlink(logFilename, linkFilename))
  	}
  
  	// need to create a log file?
  	if l.file == nil {
  		if err := openLogFile(); err != nil {
  			return trace.Wrap(err)
  		}
  		return trace.Wrap(createSymlink())
  	}
  
  	// time to advance the logfile?
  	if l.fileTime.Before(fileTime) {
  		l.file.Close()
  		if err := openLogFile(); err != nil {
  			return trace.Wrap(err)
  		}
  		return trace.Wrap(createSymlink())
  	}
  	return nil
  }
docs: // rotateLog checks if the current log file is older than a given duration,
  // and if it is, closes it and opens a new one.