From: wyjDoraemon <46176410+wyjDoraemon@users.noreply.github.com> Date: Tue, 30 Jul 2019 08:27:12 +0000 (+0800) Subject: fix dir is not exist (#368) X-Git-Tag: v1.0.5~66 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=4b8c1d52bc51d783f1fc50eaada101555e15d938;ds=sidebyside fix dir is not exist (#368) * fix dir is not exist * fix --- 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 } }