log.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package tunnelrpc
  2. import (
  3. "context"
  4. "github.com/cloudflare/cloudflared/logger"
  5. "golang.org/x/net/trace"
  6. "zombiezen.com/go/capnproto2/rpc"
  7. )
  8. // ConnLogger wraps a logrus *log.Entry for a connection.
  9. type ConnLogger struct {
  10. Entry logger.Service
  11. }
  12. func (c ConnLogger) Infof(ctx context.Context, format string, args ...interface{}) {
  13. c.Entry.Infof(format, args...)
  14. }
  15. func (c ConnLogger) Errorf(ctx context.Context, format string, args ...interface{}) {
  16. c.Entry.Errorf(format, args...)
  17. }
  18. func ConnLog(log logger.Service) rpc.ConnOption {
  19. return rpc.ConnLog(ConnLogger{log})
  20. }
  21. // ConnTracer wraps a trace.EventLog for a connection.
  22. type ConnTracer struct {
  23. Events trace.EventLog
  24. }
  25. func (c ConnTracer) Infof(ctx context.Context, format string, args ...interface{}) {
  26. c.Events.Printf(format, args...)
  27. }
  28. func (c ConnTracer) Errorf(ctx context.Context, format string, args ...interface{}) {
  29. c.Events.Errorf(format, args...)
  30. }
  31. func ConnTrace(events trace.EventLog) rpc.ConnOption {
  32. return rpc.ConnLog(ConnTracer{events})
  33. }