github.com/danielpfeifer02/quic-go-prio-packs@v0.41.0-28/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/danielpfeifer02/quic-go-prio-packs" 12 "github.com/danielpfeifer02/quic-go-prio-packs/internal/utils" 13 "github.com/danielpfeifer02/quic-go-prio-packs/logging" 14 "github.com/danielpfeifer02/quic-go-prio-packs/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_%s_%s.qlog", connID, 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 }