2018-05-01 23:45:06 +00:00
|
|
|
package tunnelrpc
|
|
|
|
|
|
|
|
import (
|
2019-01-10 20:55:44 +00:00
|
|
|
"context"
|
|
|
|
|
2020-04-29 20:51:32 +00:00
|
|
|
"github.com/cloudflare/cloudflared/logger"
|
2018-05-01 23:45:06 +00:00
|
|
|
"golang.org/x/net/trace"
|
|
|
|
"zombiezen.com/go/capnproto2/rpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ConnLogger wraps a logrus *log.Entry for a connection.
|
|
|
|
type ConnLogger struct {
|
2020-04-29 20:51:32 +00:00
|
|
|
Entry logger.Service
|
2018-05-01 23:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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...)
|
|
|
|
}
|
|
|
|
|
2020-04-29 20:51:32 +00:00
|
|
|
func ConnLog(log logger.Service) rpc.ConnOption {
|
2018-05-01 23:45:06 +00:00
|
|
|
return rpc.ConnLog(ConnLogger{log})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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})
|
|
|
|
}
|