example: remove -v flag and custom logger configuration (#4242)

Users can adjust the log level using the QUIC_GO_LOG_LEVEL environment
variable. This is more representative of how quic-go would actually be
used, since the logger is part of an internal package.
This commit is contained in:
Marten Seemann 2024-01-13 16:59:58 +07:00 committed by GitHub
parent 2cd9ed38f1
commit 13327521a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 26 deletions

View file

@ -23,7 +23,6 @@ import (
) )
func main() { func main() {
verbose := flag.Bool("v", false, "verbose")
quiet := flag.Bool("q", false, "don't print the data") quiet := flag.Bool("q", false, "don't print the data")
keyLogFile := flag.String("keylog", "", "key log file") keyLogFile := flag.String("keylog", "", "key log file")
insecure := flag.Bool("insecure", false, "skip certificate verification") insecure := flag.Bool("insecure", false, "skip certificate verification")
@ -31,15 +30,6 @@ func main() {
flag.Parse() flag.Parse()
urls := flag.Args() urls := flag.Args()
logger := utils.DefaultLogger
if *verbose {
logger.SetLogLevel(utils.LogLevelDebug)
} else {
logger.SetLogLevel(utils.LogLevelInfo)
}
logger.SetLogTimeFormat("")
var keyLog io.Writer var keyLog io.Writer
if len(*keyLogFile) > 0 { if len(*keyLogFile) > 0 {
f, err := os.Create(*keyLogFile) f, err := os.Create(*keyLogFile)
@ -84,13 +74,13 @@ func main() {
var wg sync.WaitGroup var wg sync.WaitGroup
wg.Add(len(urls)) wg.Add(len(urls))
for _, addr := range urls { for _, addr := range urls {
logger.Infof("GET %s", addr) log.Printf("GET %s", addr)
go func(addr string) { go func(addr string) {
rsp, err := hclient.Get(addr) rsp, err := hclient.Get(addr)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
logger.Infof("Got response for %s: %#v", addr, rsp) log.Printf("Got response for %s: %#v", addr, rsp)
body := &bytes.Buffer{} body := &bytes.Buffer{}
_, err = io.Copy(body, rsp.Body) _, err = io.Copy(body, rsp.Body)
@ -98,10 +88,9 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
if *quiet { if *quiet {
logger.Infof("Response Body: %d bytes", body.Len()) log.Printf("Response Body: %d bytes", body.Len())
} else { } else {
logger.Infof("Response Body:") log.Printf("Response Body (%d bytes):\n%s", body.Len(), body.Bytes())
logger.Infof("%s", body.Bytes())
} }
wg.Done() wg.Done()
}(addr) }(addr)

View file

@ -121,7 +121,7 @@ func setupHandler(www string) http.Handler {
err = errors.New("couldn't get uploaded file size") err = errors.New("couldn't get uploaded file size")
} }
} }
utils.DefaultLogger.Infof("Error receiving upload: %#v", err) log.Printf("Error receiving upload: %#v", err)
} }
io.WriteString(w, `<html><body><form action="/demo/upload" method="post" enctype="multipart/form-data"> io.WriteString(w, `<html><body><form action="/demo/upload" method="post" enctype="multipart/form-data">
<input type="file" name="uploadfile"><br> <input type="file" name="uploadfile"><br>
@ -139,7 +139,6 @@ func main() {
}() }()
// runtime.SetBlockProfileRate(1) // runtime.SetBlockProfileRate(1)
verbose := flag.Bool("v", false, "verbose")
bs := binds{} bs := binds{}
flag.Var(&bs, "bind", "bind to") flag.Var(&bs, "bind", "bind to")
www := flag.String("www", "", "www data") www := flag.String("www", "", "www data")
@ -149,15 +148,6 @@ func main() {
enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)") enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
flag.Parse() flag.Parse()
logger := utils.DefaultLogger
if *verbose {
logger.SetLogLevel(utils.LogLevelDebug)
} else {
logger.SetLogLevel(utils.LogLevelInfo)
}
logger.SetLogTimeFormat("")
if len(bs) == 0 { if len(bs) == 0 {
bs = binds{"localhost:6121"} bs = binds{"localhost:6121"}
} }