github.com/MerlinKodo/quic-go@v0.39.2/integrationtests/tools/qlog.go (about) 1 package tools 2 3 import ( 4 "bufio" 5 "context" 6 "fmt" 7 "io" 8 "log" 9 "os" 10 11 "github.com/MerlinKodo/quic-go" 12 "github.com/MerlinKodo/quic-go/internal/utils" 13 "github.com/MerlinKodo/quic-go/logging" 14 "github.com/MerlinKodo/quic-go/qlog" 15 ) 16 17 func NewQlogger(logger io.Writer) func(context.Context, logging.Perspective, quic.ConnectionID) *logging.ConnectionTracer { 18 return func(_ context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer { 19 role := "server" 20 if p == logging.PerspectiveClient { 21 role = "client" 22 } 23 filename := fmt.Sprintf("log_%x_%s.qlog", connID.Bytes(), role) 24 fmt.Fprintf(logger, "Creating %s.\n", filename) 25 f, err := os.Create(filename) 26 if err != nil { 27 log.Fatalf("failed to create qlog file: %s", err) 28 return nil 29 } 30 bw := bufio.NewWriter(f) 31 return qlog.NewConnectionTracer(utils.NewBufferedWriteCloser(bw, f), p, connID) 32 } 33 }