qoobing.com/gomod/log@v1.2.8/util.go (about)

     1  package log
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  )
     8  
     9  // getExeFilename
    10  func getExeFilename() string {
    11  	_, logfilename := filepath.Split(os.Args[0])
    12  	if logfilename == "" {
    13  		panic("get exe filename failed")
    14  	}
    15  	return logfilename
    16  }
    17  
    18  // tryOptLogDirs
    19  func tryOptLogDirs(optLogDirs []string) (string, error) {
    20  	optionDirsStr := ""
    21  	for i, d := range optLogDirs {
    22  		dir := fmt.Sprintf("%s/", d)
    23  		optionDirsStr += fmt.Sprintf("%d.[%s];", i, dir)
    24  		if _, err := os.Stat(dir); err == nil {
    25  			return dir, nil
    26  		}
    27  	}
    28  	return "", fmt.Errorf("all optional dir are not exist: %s", optionDirsStr)
    29  }