forked from quic-go/quic-go
remove Tracer from Config, put ConnectionTracer constructor there
This commit is contained in:
21
qlog/qlog.go
21
qlog/qlog.go
@@ -2,7 +2,6 @@ package qlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
@@ -49,26 +48,6 @@ func init() {
|
||||
|
||||
const eventChanSize = 50
|
||||
|
||||
type tracer struct {
|
||||
logging.NullTracer
|
||||
|
||||
getLogWriter func(p logging.Perspective, connectionID []byte) io.WriteCloser
|
||||
}
|
||||
|
||||
var _ logging.Tracer = &tracer{}
|
||||
|
||||
// NewTracer creates a new qlog tracer.
|
||||
func NewTracer(getLogWriter func(p logging.Perspective, connectionID []byte) io.WriteCloser) logging.Tracer {
|
||||
return &tracer{getLogWriter: getLogWriter}
|
||||
}
|
||||
|
||||
func (t *tracer) TracerForConnection(_ context.Context, p logging.Perspective, odcid protocol.ConnectionID) logging.ConnectionTracer {
|
||||
if w := t.getLogWriter(p, odcid.Bytes()); w != nil {
|
||||
return NewConnectionTracer(w, p, odcid)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type connectionTracer struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package qlog
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
@@ -51,17 +50,6 @@ type entry struct {
|
||||
}
|
||||
|
||||
var _ = Describe("Tracing", func() {
|
||||
Context("tracer", func() {
|
||||
It("returns nil when there's no io.WriteCloser", func() {
|
||||
t := NewTracer(func(logging.Perspective, []byte) io.WriteCloser { return nil })
|
||||
Expect(t.TracerForConnection(
|
||||
context.Background(),
|
||||
logging.PerspectiveClient,
|
||||
protocol.ParseConnectionID([]byte{1, 2, 3, 4}),
|
||||
)).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
It("stops writing when encountering an error", func() {
|
||||
buf := &bytes.Buffer{}
|
||||
t := NewConnectionTracer(
|
||||
@@ -88,9 +76,8 @@ var _ = Describe("Tracing", func() {
|
||||
|
||||
BeforeEach(func() {
|
||||
buf = &bytes.Buffer{}
|
||||
t := NewTracer(func(logging.Perspective, []byte) io.WriteCloser { return nopWriteCloser(buf) })
|
||||
tracer = t.TracerForConnection(
|
||||
context.Background(),
|
||||
tracer = NewConnectionTracer(
|
||||
nopWriteCloser(buf),
|
||||
logging.PerspectiveServer,
|
||||
protocol.ParseConnectionID([]byte{0xde, 0xad, 0xbe, 0xef}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user