OSDN Git Service

fix dir is not exist (#368)
[bytom/vapor.git] / log / log.go
index ebd979f..c766483 100644 (file)
@@ -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
                        }
                }