Skip to content

Commit 83169c8

Browse files
author
Qiao Liang
committed
allow basic logging for http Get err with RegisterErrLogFn
1 parent 72d04f9 commit 83169c8

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

groupcache.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var (
6060

6161
initPeerServerOnce sync.Once
6262
initPeerServer func()
63+
errLogFn func(error)
6364
)
6465

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

125+
// RegisterErrLogFn registers a log func that is used for http error logging
126+
func RegisterErrLogFn(fn func(error)) {
127+
if errLogFn != nil {
128+
panic("RegisterLogFunc called more than once")
129+
}
130+
errLogFn = fn
131+
}
132+
133+
func logErr(err error) {
134+
if errLogFn != nil {
135+
errLogFn(err)
136+
}
137+
}
138+
124139
// RegisterServerStart registers a hook that is run when the first
125140
// group is created.
126141
func RegisterServerStart(fn func()) {
@@ -271,10 +286,7 @@ func (g *Group) load(ctx Context, key string, dest Sink) (value ByteView, destPo
271286
return value, nil
272287
}
273288
g.Stats.PeerErrors.Add(1)
274-
// TODO(bradfitz): log the peer's error? keep
275-
// log of the past few for /groupcachez? It's
276-
// probably boring (normal task movement), so not
277-
// worth logging I imagine.
289+
logErr(err)
278290
}
279291
value, err = g.getLocally(ctx, key, dest)
280292
if err != nil {

0 commit comments

Comments
 (0)