cloudflared-mirror/tunnelrpc/log.go

43 lines
1.0 KiB
Go
Raw Normal View History

2017-10-16 11:44:03 +00:00
package tunnelrpc
import (
2018-02-20 21:13:56 +00:00
log "github.com/sirupsen/logrus"
2017-10-16 11:44:03 +00:00
"golang.org/x/net/context"
2018-02-20 21:13:56 +00:00
"golang.org/x/net/trace"
2017-10-16 11:44:03 +00:00
"zombiezen.com/go/capnproto2/rpc"
)
// ConnLogger wraps a logrus *log.Entry for a connection.
type ConnLogger struct {
Entry *log.Entry
}
func (c ConnLogger) Infof(ctx context.Context, format string, args ...interface{}) {
c.Entry.Infof(format, args...)
}
func (c ConnLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
c.Entry.Errorf(format, args...)
}
func ConnLog(log *log.Entry) rpc.ConnOption {
return rpc.ConnLog(ConnLogger{log})
}
2018-02-20 21:13:56 +00:00
// ConnTracer wraps a trace.EventLog for a connection.
type ConnTracer struct {
Events trace.EventLog
}
func (c ConnTracer) Infof(ctx context.Context, format string, args ...interface{}) {
c.Events.Printf(format, args...)
}
func (c ConnTracer) Errorf(ctx context.Context, format string, args ...interface{}) {
c.Events.Errorf(format, args...)
}
func ConnTrace(events trace.EventLog) rpc.ConnOption {
return rpc.ConnLog(ConnTracer{events})
}