Browse Source

fileutil: use leveled logging

Xiang Li 10 years ago
parent
commit
e2c2f098bc
2 changed files with 9 additions and 4 deletions
  1. 6 0
      pkg/fileutil/fileutil.go
  2. 3 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 {

+ 3 - 4
pkg/fileutil/purge.go

@@ -15,7 +15,6 @@
 package fileutil
 
 import (
-	"log"
 	"os"
 	"path"
 	"sort"
@@ -57,13 +56,13 @@ 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)
 				}
 				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)
 				}
-				log.Printf("filePurge: successfully removed file %s", f)
+				plog.Infof("purged file %s successfully", f)
 				newfnames = newfnames[1:]
 			}
 			select {