cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
tunnelrpc/log.go
42lines · modecode
| 1 | package tunnelrpc |
| 2 | |
| 3 | import ( |
| 4 | log "github.com/sirupsen/logrus" |
| 5 | "golang.org/x/net/context" |
| 6 | "golang.org/x/net/trace" |
| 7 | "zombiezen.com/go/capnproto2/rpc" |
| 8 | ) |
| 9 | |
| 10 | // ConnLogger wraps a logrus *log.Entry for a connection. |
| 11 | type ConnLogger struct { |
| 12 | Entry *log.Entry |
| 13 | } |
| 14 | |
| 15 | func (c ConnLogger) Infof(ctx context.Context, format string, args ...interface{}) { |
| 16 | c.Entry.Infof(format, args...) |
| 17 | } |
| 18 | |
| 19 | func (c ConnLogger) Errorf(ctx context.Context, format string, args ...interface{}) { |
| 20 | c.Entry.Errorf(format, args...) |
| 21 | } |
| 22 | |
| 23 | func ConnLog(log *log.Entry) rpc.ConnOption { |
| 24 | return rpc.ConnLog(ConnLogger{log}) |
| 25 | } |
| 26 | |
| 27 | // ConnTracer wraps a trace.EventLog for a connection. |
| 28 | type ConnTracer struct { |
| 29 | Events trace.EventLog |
| 30 | } |
| 31 | |
| 32 | func (c ConnTracer) Infof(ctx context.Context, format string, args ...interface{}) { |
| 33 | c.Events.Printf(format, args...) |
| 34 | } |
| 35 | |
| 36 | func (c ConnTracer) Errorf(ctx context.Context, format string, args ...interface{}) { |
| 37 | c.Events.Errorf(format, args...) |
| 38 | } |
| 39 | |
| 40 | func ConnTrace(events trace.EventLog) rpc.ConnOption { |
| 41 | return rpc.ConnLog(ConnTracer{events}) |
| 42 | } |
| 43 | |