Merge pull request #2896 from xiang90/wal_log

wal: use leveled logger
This commit is contained in:
Xiang Li 2015-06-02 11:39:25 -07:00
commit 46b5eb051e
2 changed files with 9 additions and 8 deletions

View File

@ -17,7 +17,6 @@ package wal
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"strings" "strings"
"github.com/coreos/etcd/pkg/fileutil" "github.com/coreos/etcd/pkg/fileutil"
@ -43,7 +42,7 @@ func searchIndex(names []string, index uint64) (int, bool) {
name := names[i] name := names[i]
_, curIndex, err := parseWalName(name) _, curIndex, err := parseWalName(name)
if err != nil { 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 { if index >= curIndex {
return i, true return i, true
@ -59,7 +58,7 @@ func isValidSeq(names []string) bool {
for _, name := range names { for _, name := range names {
curSeq, _, err := parseWalName(name) curSeq, _, err := parseWalName(name)
if err != nil { 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 { if lastSeq != 0 && lastSeq != curSeq-1 {
return false return false
@ -73,7 +72,7 @@ func checkWalNames(names []string) []string {
wnames := make([]string, 0) wnames := make([]string, 0)
for _, name := range names { for _, name := range names {
if _, _, err := parseWalName(name); err != nil { if _, _, err := parseWalName(name); err != nil {
log.Printf("wal: ignored file %v in wal", name) logger.Warningf("ignored file %v in wal", name)
continue continue
} }
wnames = append(wnames, name) wnames = append(wnames, name)

View File

@ -19,7 +19,6 @@ import (
"fmt" "fmt"
"hash/crc32" "hash/crc32"
"io" "io"
"log"
"os" "os"
"path" "path"
"reflect" "reflect"
@ -31,6 +30,8 @@ import (
"github.com/coreos/etcd/raft" "github.com/coreos/etcd/raft"
"github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/raft/raftpb"
"github.com/coreos/etcd/wal/walpb" "github.com/coreos/etcd/wal/walpb"
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/pkg/capnslog"
) )
const ( const (
@ -49,6 +50,8 @@ const (
) )
var ( var (
logger = capnslog.NewPackageLogger("github.com/coreos/etcd", "wal")
ErrMetadataConflict = errors.New("wal: conflicting metadata found") ErrMetadataConflict = errors.New("wal: conflicting metadata found")
ErrFileNotFound = errors.New("wal: file not found") ErrFileNotFound = errors.New("wal: file not found")
ErrCRCMismatch = errors.New("wal: crc mismatch") ErrCRCMismatch = errors.New("wal: crc mismatch")
@ -172,7 +175,7 @@ func openAtIndex(dirpath string, snap walpb.Snapshot, all bool) (*WAL, error) {
if all { if all {
return nil, err return nil, err
} else { } 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 break
} }
} }
@ -353,8 +356,7 @@ func (w *WAL) cut() error {
// increase the wal seq // increase the wal seq
w.seq++ w.seq++
log.Printf("wal: segmented wal file %v is created", fpath) logger.Infof("segmented wal file %v is created", fpath)
return nil return nil
} }