From 13327521a55ab36e2938632d8b7cedba32552f57 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 13 Jan 2024 16:59:58 +0700 Subject: [PATCH] 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. --- example/client/main.go | 19 ++++--------------- example/main.go | 12 +----------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/example/client/main.go b/example/client/main.go index 847acb72..72b51093 100644 --- a/example/client/main.go +++ b/example/client/main.go @@ -23,7 +23,6 @@ import ( ) func main() { - verbose := flag.Bool("v", false, "verbose") quiet := flag.Bool("q", false, "don't print the data") keyLogFile := flag.String("keylog", "", "key log file") insecure := flag.Bool("insecure", false, "skip certificate verification") @@ -31,15 +30,6 @@ func main() { flag.Parse() urls := flag.Args() - logger := utils.DefaultLogger - - if *verbose { - logger.SetLogLevel(utils.LogLevelDebug) - } else { - logger.SetLogLevel(utils.LogLevelInfo) - } - logger.SetLogTimeFormat("") - var keyLog io.Writer if len(*keyLogFile) > 0 { f, err := os.Create(*keyLogFile) @@ -84,13 +74,13 @@ func main() { var wg sync.WaitGroup wg.Add(len(urls)) for _, addr := range urls { - logger.Infof("GET %s", addr) + log.Printf("GET %s", addr) go func(addr string) { rsp, err := hclient.Get(addr) if err != nil { log.Fatal(err) } - logger.Infof("Got response for %s: %#v", addr, rsp) + log.Printf("Got response for %s: %#v", addr, rsp) body := &bytes.Buffer{} _, err = io.Copy(body, rsp.Body) @@ -98,10 +88,9 @@ func main() { log.Fatal(err) } if *quiet { - logger.Infof("Response Body: %d bytes", body.Len()) + log.Printf("Response Body: %d bytes", body.Len()) } else { - logger.Infof("Response Body:") - logger.Infof("%s", body.Bytes()) + log.Printf("Response Body (%d bytes):\n%s", body.Len(), body.Bytes()) } wg.Done() }(addr) diff --git a/example/main.go b/example/main.go index 014003f6..5ee426cc 100644 --- a/example/main.go +++ b/example/main.go @@ -121,7 +121,7 @@ func setupHandler(www string) http.Handler { 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, `

@@ -139,7 +139,6 @@ func main() { }() // runtime.SetBlockProfileRate(1) - verbose := flag.Bool("v", false, "verbose") bs := binds{} flag.Var(&bs, "bind", "bind to") www := flag.String("www", "", "www data") @@ -149,15 +148,6 @@ func main() { enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)") flag.Parse() - logger := utils.DefaultLogger - - if *verbose { - logger.SetLogLevel(utils.LogLevelDebug) - } else { - logger.SetLogLevel(utils.LogLevelInfo) - } - logger.SetLogTimeFormat("") - if len(bs) == 0 { bs = binds{"localhost:6121"} }