From 4b8c1d52bc51d783f1fc50eaada101555e15d938 Mon Sep 17 00:00:00 2001 From: wyjDoraemon <46176410+wyjDoraemon@users.noreply.github.com> Date: Tue, 30 Jul 2019 16:27:12 +0800 Subject: [PATCH] fix dir is not exist (#368) * fix dir is not exist * fix --- log/log.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/log/log.go b/log/log.go index ebd979f4..c7664834 100644 --- a/log/log.go +++ b/log/log.go @@ -30,7 +30,7 @@ func InitLogFile(config *config.Config) error { hook := newBtmHook(logPath) logrus.AddHook(hook) - logrus.SetOutput(ioutil.Discard)//控制台不输出 + logrus.SetOutput(ioutil.Discard) //控制台不输出 fmt.Printf("all logs are output in the %s directory\n", logPath) return nil } @@ -74,13 +74,15 @@ func (hook *BtmHook) ioWrite(entry *logrus.Entry) error { func clearLockFiles(logPath string) error { files, err := ioutil.ReadDir(logPath) - if err != nil { + if os.IsNotExist(err) { + return nil + }else if err != nil { return err } for _, file := range files { if ok := strings.HasSuffix(file.Name(), "_lock"); ok { - if err := os.Remove(filepath.Join(logPath, file.Name()));err!=nil{ + if err := os.Remove(filepath.Join(logPath, file.Name())); err != nil { return err } } -- 2.11.0