Skip to content

Commit

Permalink
allow basic logging for http Get err with RegisterErrLogFn
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiao Liang committed Apr 11, 2017
1 parent 72d04f9 commit 83169c8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions groupcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (

initPeerServerOnce sync.Once
initPeerServer func()
errLogFn func(error)
)

// GetGroup returns the named group previously created with NewGroup, or
Expand Down Expand Up @@ -121,6 +122,20 @@ func RegisterNewGroupHook(fn func(*Group)) {
newGroupHook = fn
}

// RegisterErrLogFn registers a log func that is used for http error logging
func RegisterErrLogFn(fn func(error)) {
if errLogFn != nil {
panic("RegisterLogFunc called more than once")
}
errLogFn = fn
}

func logErr(err error) {
if errLogFn != nil {
errLogFn(err)
}
}

// RegisterServerStart registers a hook that is run when the first
// group is created.
func RegisterServerStart(fn func()) {
Expand Down Expand Up @@ -271,10 +286,7 @@ func (g *Group) load(ctx Context, key string, dest Sink) (value ByteView, destPo
return value, nil
}
g.Stats.PeerErrors.Add(1)
// TODO(bradfitz): log the peer's error? keep
// log of the past few for /groupcachez? It's
// probably boring (normal task movement), so not
// worth logging I imagine.
logErr(err)
}
value, err = g.getLocally(ctx, key, dest)
if err != nil {
Expand Down

0 comments on commit 83169c8

Please sign in to comment.