package qlog

import (
	
	
	
	
	
	
	

	
	
)

// EventSchema is the qlog event schema for QUIC
const EventSchema = "urn:ietf:params:qlog:events:quic-12"

// DefaultConnectionTracer creates a qlog file in the qlog directory specified by the QLOGDIR environment variable.
// File names are <odcid>_<perspective>.sqlog.
// Returns nil if QLOGDIR is not set.
func ( context.Context,  bool,  ConnectionID) qlogwriter.Trace {
	return defaultConnectionTracerWithSchemas(, , []string{EventSchema})
}

func ( context.Context,  bool,  ConnectionID,  []string) qlogwriter.Trace {
	if !slices.Contains(, EventSchema) {
		 = append([]string{EventSchema}, ...)
	}
	return defaultConnectionTracerWithSchemas(, , )
}

func defaultConnectionTracerWithSchemas( bool,  ConnectionID,  []string) qlogwriter.Trace {
	 := os.Getenv("QLOGDIR")
	if  == "" {
		return nil
	}
	if ,  := os.Stat(); os.IsNotExist() {
		if  := os.MkdirAll(, 0o755);  != nil {
			log.Fatalf("failed to create qlog dir %s: %v", , )
		}
	}
	 := "server"
	if  {
		 = "client"
	}
	 := fmt.Sprintf("%s/%s_%s.sqlog", strings.TrimRight(, "/"), , )
	,  := os.Create()
	if  != nil {
		log.Printf("Failed to create qlog file %s: %s", , .Error())
		return nil
	}
	 := qlogwriter.NewConnectionFileSeq(
		utils.NewBufferedWriteCloser(bufio.NewWriter(), ),
		,
		,
		,
	)
	go .Run()
	return 
}