diff --git a/QMPlusServer/init/qmlog/qmlog.go b/QMPlusServer/init/qmlog/qmlog.go index 5956ed0bf38d3ec39e1c3b1e462b8da0dc0e5816..c7eceba6613d78b606d64bbedc868770ed082b04 100644 --- a/QMPlusServer/init/qmlog/qmlog.go +++ b/QMPlusServer/init/qmlog/qmlog.go @@ -6,6 +6,7 @@ import ( rotatelogs "github.com/lestrrat/go-file-rotatelogs" "github.com/rifflock/lfshook" "github.com/sirupsen/logrus" + "main/tools" "os" "time" ) @@ -19,6 +20,11 @@ func InitLog() *logrus.Logger{ } QMLog.Out = src QMLog.SetLevel(logrus.DebugLevel) + if ok, _ := tools.PathExists("./log"); !ok { + // Directory not exist + fmt.Println("Create log.") + os.Mkdir("log", os.ModePerm) + } apiLogPath := "./log/api.log" logWriter, err := rotatelogs.New( apiLogPath+".%Y-%m-%d-%H-%M.log", diff --git a/QMPlusServer/tools/directory.go b/QMPlusServer/tools/directory.go new file mode 100644 index 0000000000000000000000000000000000000000..1f03da9db91d10805e6709af358353505e18accf --- /dev/null +++ b/QMPlusServer/tools/directory.go @@ -0,0 +1,14 @@ +package tools + +import "os" + +func PathExists(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return false, err +}