| | |
| | | |
| | | import ( |
| | | "io/ioutil" |
| | | "os" |
| | | "os/exec" |
| | | "path/filepath" |
| | | "time" |
| | | |
| | | rotatelogs "github.com/lestrrat-go/file-rotatelogs" |
| | |
| | | if Log != nil { |
| | | return Log |
| | | } |
| | | |
| | | infopath := "logs/info.log" |
| | | rootPath := GetAppRootPath() |
| | | infopath := rootPath + "/logs/info.log" |
| | | infowriter, _ := rotatelogs.New( |
| | | infopath+".%Y%m%d%H%M", |
| | | rotatelogs.WithLinkName(infopath), |
| | |
| | | rotatelogs.WithRotationTime(24*time.Hour), |
| | | ) |
| | | |
| | | errorpath := "logs/error.log" |
| | | errorpath := rootPath + "/logs/error.log" |
| | | errorwriter, _ := rotatelogs.New( |
| | | errorpath+".%Y%m%d%H%M", |
| | | rotatelogs.WithLinkName(errorpath), |
| | |
| | | )) |
| | | return Log |
| | | } |
| | | |
| | | func GetAppRootPath() string { |
| | | file,err:= exec.LookPath(os.Args[0]) |
| | | if err != nil { |
| | | return "" |
| | | } |
| | | p, err := filepath.Abs(file) |
| | | if err != nil { |
| | | return "" |
| | | } |
| | | return filepath.Dir(p) |
| | | } |