Browse Source
Merge pull request #13 from granty1/master
Add check for log directory.
main
蒋吉兆
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
20 additions and
0 deletions
-
QMPlusServer/init/qmlog/qmlog.go
-
QMPlusServer/tools/directory.go
|
@ -6,6 +6,7 @@ import ( |
|
|
rotatelogs "github.com/lestrrat/go-file-rotatelogs" |
|
|
rotatelogs "github.com/lestrrat/go-file-rotatelogs" |
|
|
"github.com/rifflock/lfshook" |
|
|
"github.com/rifflock/lfshook" |
|
|
"github.com/sirupsen/logrus" |
|
|
"github.com/sirupsen/logrus" |
|
|
|
|
|
"main/tools" |
|
|
"os" |
|
|
"os" |
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
@ -19,6 +20,11 @@ func InitLog() *logrus.Logger{ |
|
|
} |
|
|
} |
|
|
QMLog.Out = src |
|
|
QMLog.Out = src |
|
|
QMLog.SetLevel(logrus.DebugLevel) |
|
|
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" |
|
|
apiLogPath := "./log/api.log" |
|
|
logWriter, err := rotatelogs.New( |
|
|
logWriter, err := rotatelogs.New( |
|
|
apiLogPath+".%Y-%m-%d-%H-%M.log", |
|
|
apiLogPath+".%Y-%m-%d-%H-%M.log", |
|
|
|
@ -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 |
|
|
|
|
|
} |