forked from capnproto/go-capnp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
49 lines (40 loc) · 1.21 KB
/
log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package rpc
import (
"log"
"golang.org/x/net/context"
)
// A Logger records diagnostic information and errors that are not
// associated with a call. The arguments passed into a log call are
// interpreted like fmt.Printf. They should not be held onto past the
// call's return.
type Logger interface {
Infof(ctx context.Context, format string, args ...interface{})
Errorf(ctx context.Context, format string, args ...interface{})
}
type defaultLogger struct{}
func (defaultLogger) Infof(ctx context.Context, format string, args ...interface{}) {
log.Printf("rpc: "+format, args...)
}
func (defaultLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
log.Printf("rpc: "+format, args...)
}
func (c *Conn) infof(format string, args ...interface{}) {
if c.log == nil {
return
}
c.log.Infof(c.bg, format, args...)
}
func (c *Conn) errorf(format string, args ...interface{}) {
if c.log == nil {
return
}
c.log.Errorf(c.bg, format, args...)
}
// ConnLog sets the connection's log to the given Logger, which may be
// nil to disable logging. By default, logs are sent to the standard
// log package.
func ConnLog(log Logger) ConnOption {
return ConnOption{func(c *connParams) {
c.log = log
}}
}