forked from quic-go/quic-go
export qlog files if the QLOGDIR env is set in interop client and server
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetSSLKeyLog creates a file for the TLS key log
|
||||
@@ -17,3 +20,24 @@ func GetSSLKeyLog() (io.WriteCloser, error) {
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// GetQLOGWriter creates the QLOGDIR and returns the GetLogWriter callback
|
||||
func GetQLOGWriter() (func(connID []byte) io.WriteCloser, error) {
|
||||
qlogDir := os.Getenv("QLOGDIR")
|
||||
if len(qlogDir) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if _, err := os.Stat(qlogDir); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(qlogDir, 0666); err != nil {
|
||||
return nil, fmt.Errorf("failed to create qlog dir %s: %s", qlogDir, err.Error())
|
||||
}
|
||||
}
|
||||
return func(connID []byte) io.WriteCloser {
|
||||
path := fmt.Sprintf("%s/%x.qlog", strings.TrimRight(qlogDir, "/"), connID)
|
||||
f, err := os.Create(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create qlog file %s: %s", path, err.Error())
|
||||
}
|
||||
return f
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user