未验证 提交 854b96ff 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

Merge pull request #13 from granty1/master

Add check for log directory.
......@@ -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",
......
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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册