Skip to content

Commit

Permalink
logging: add a Debug function to the Tracer
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Feb 2, 2024
1 parent d83c51b commit e93189d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions internal/mocks/logging/internal/tracer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions internal/mocks/logging/mockgen.go
Expand Up @@ -14,6 +14,7 @@ type Tracer interface {
SentPacket(net.Addr, *logging.Header, logging.ByteCount, []logging.Frame)
SentVersionNegotiationPacket(_ net.Addr, dest, src logging.ArbitraryLenConnectionID, _ []logging.VersionNumber)
DroppedPacket(net.Addr, logging.PacketType, logging.ByteCount, logging.PacketDropReason)
Debug(name, msg string)
}

//go:generate sh -c "go run go.uber.org/mock/mockgen -typed -build_flags=\"-tags=gomock\" -package internal -destination internal/connection_tracer.go github.com/quic-go/quic-go/internal/mocks/logging ConnectionTracer"
Expand Down
3 changes: 3 additions & 0 deletions internal/mocks/logging/tracer.go
Expand Up @@ -25,5 +25,8 @@ func NewMockTracer(ctrl *gomock.Controller) (*logging.Tracer, *MockTracer) {
DroppedPacket: func(remote net.Addr, typ logging.PacketType, size logging.ByteCount, reason logging.PacketDropReason) {
t.DroppedPacket(remote, typ, size, reason)
},
Debug: func(name, msg string) {
t.Debug(name, msg)
},
}, t
}
6 changes: 6 additions & 0 deletions logging/multiplex_test.go
Expand Up @@ -64,6 +64,12 @@ var _ = Describe("Tracing", func() {
tr2.EXPECT().DroppedPacket(remote, PacketTypeRetry, ByteCount(1024), PacketDropDuplicate)
tracer.DroppedPacket(remote, PacketTypeRetry, 1024, PacketDropDuplicate)
})

It("traces the Debug event", func() {
tr1.EXPECT().Debug("foo", "bar")
tr2.EXPECT().Debug("foo", "bar")
tracer.Debug("foo", "bar")
})
})
})

Expand Down
8 changes: 8 additions & 0 deletions logging/tracer.go
Expand Up @@ -7,6 +7,7 @@ type Tracer struct {
SentPacket func(net.Addr, *Header, ByteCount, []Frame)
SentVersionNegotiationPacket func(_ net.Addr, dest, src ArbitraryLenConnectionID, _ []VersionNumber)
DroppedPacket func(net.Addr, PacketType, ByteCount, PacketDropReason)
Debug func(name, msg string)
}

// NewMultiplexedTracer creates a new tracer that multiplexes events to multiple tracers.
Expand Down Expand Up @@ -39,5 +40,12 @@ func NewMultiplexedTracer(tracers ...*Tracer) *Tracer {
}
}
},
Debug: func(name, msg string) {
for _, t := range tracers {
if t.Debug != nil {
t.Debug(name, msg)
}
}
},
}
}

0 comments on commit e93189d

Please sign in to comment.