logging: add a Debug function to the Tracer (#4297)

This commit is contained in:
Marten Seemann
2024-02-03 11:21:27 +07:00
committed by GitHub
parent 225d2a3926
commit b675e34254
5 changed files with 54 additions and 0 deletions

View File

@@ -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")
})
})
})

View File

@@ -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.
@@ -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)
}
}
},
}
}