Browse Source

Merge pull request #2952 from xiang90/fileutil

fileutil: use leveled logging
Xiang Li 10 năm trước cách đây
mục cha
commit
f64a8214f7
2 tập tin đã thay đổi với 13 bổ sung4 xóa
  1. 6 0
      pkg/fileutil/fileutil.go
  2. 7 4
      pkg/fileutil/purge.go

+ 6 - 0
pkg/fileutil/fileutil.go

@@ -19,12 +19,18 @@ import (
 	"os"
 	"path"
 	"sort"
+
+	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
 )
 
 const (
 	privateFileMode = 0600
 )
 
+var (
+	plog = capnslog.NewPackageLogger("github.com/coreos/etcd/pkg", "fileutil")
+)
+
 // IsDirWriteable checks if dir is writable by writing and removing a file
 // to dir. It returns nil if dir is writable.
 func IsDirWriteable(dir string) error {

+ 7 - 4
pkg/fileutil/purge.go

@@ -15,7 +15,6 @@
 package fileutil
 
 import (
-	"log"
 	"os"
 	"path"
 	"sort"
@@ -57,13 +56,17 @@ func PurgeFile(dirname string, suffix string, max uint, interval time.Duration,
 				}
 				err = l.Unlock()
 				if err != nil {
-					log.Printf("filePurge: unlock %s error %v", l.Name(), err)
+					plog.Errorf("error unlocking %s when purging file (%v)", l.Name(), err)
+					errC <- err
+					return
 				}
 				err = l.Destroy()
 				if err != nil {
-					log.Printf("filePurge: destroy lock %s error %v", l.Name(), err)
+					plog.Errorf("error destroying lock %s when purging file (%v)", l.Name(), err)
+					errC <- err
+					return
 				}
-				log.Printf("filePurge: successfully removed file %s", f)
+				plog.Infof("purged file %s successfully", f)
 				newfnames = newfnames[1:]
 			}
 			select {