From 185d2bced49caccc50e9b68271c381f6e39f72a4 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 1 Jun 2015 13:38:50 -0700 Subject: [PATCH] wal: use leveled logger --- wal/util.go | 7 +++---- wal/wal.go | 10 ++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/wal/util.go b/wal/util.go index e886a5a6e..cdd5ed928 100644 --- a/wal/util.go +++ b/wal/util.go @@ -17,7 +17,6 @@ package wal import ( "errors" "fmt" - "log" "strings" "github.com/coreos/etcd/pkg/fileutil" @@ -43,7 +42,7 @@ func searchIndex(names []string, index uint64) (int, bool) { name := names[i] _, curIndex, err := parseWalName(name) if err != nil { - log.Panicf("parse correct name should never fail: %v", err) + logger.Panicf("parse correct name should never fail: %v", err) } if index >= curIndex { return i, true @@ -59,7 +58,7 @@ func isValidSeq(names []string) bool { for _, name := range names { curSeq, _, err := parseWalName(name) if err != nil { - log.Panicf("parse correct name should never fail: %v", err) + logger.Panicf("parse correct name should never fail: %v", err) } if lastSeq != 0 && lastSeq != curSeq-1 { return false @@ -73,7 +72,7 @@ func checkWalNames(names []string) []string { wnames := make([]string, 0) for _, name := range names { if _, _, err := parseWalName(name); err != nil { - log.Printf("wal: ignored file %v in wal", name) + logger.Warningf("ignored file %v in wal", name) continue } wnames = append(wnames, name) diff --git a/wal/wal.go b/wal/wal.go index 153578f14..af41d146f 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -19,7 +19,6 @@ import ( "fmt" "hash/crc32" "io" - "log" "os" "path" "reflect" @@ -31,6 +30,8 @@ import ( "github.com/coreos/etcd/raft" "github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/wal/walpb" + + "github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog" ) const ( @@ -49,6 +50,8 @@ const ( ) var ( + logger = capnslog.NewPackageLogger("github.com/coreos/etcd", "wal") + ErrMetadataConflict = errors.New("wal: conflicting metadata found") ErrFileNotFound = errors.New("wal: file not found") ErrCRCMismatch = errors.New("wal: crc mismatch") @@ -172,7 +175,7 @@ func openAtIndex(dirpath string, snap walpb.Snapshot, all bool) (*WAL, error) { if all { return nil, err } else { - log.Printf("wal: opened all the files until %s, since it is still in use by an etcd server", name) + logger.Warningf("opened all the files until %s, since it is still in use by an etcd server", name) break } } @@ -353,8 +356,7 @@ func (w *WAL) cut() error { // increase the wal seq w.seq++ - log.Printf("wal: segmented wal file %v is created", fpath) - + logger.Infof("segmented wal file %v is created", fpath) return nil }