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