Skip to content

Commit

Permalink
example: remove -v flag and custom logger configuration (quic-go#4242)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
marten-seemann authored and Constantine Shablia committed Feb 1, 2024
1 parent 355f87a commit 96b290f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
19 changes: 4 additions & 15 deletions example/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,13 @@ 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")
enableQlog := flag.Bool("qlog", false, "output a qlog (in the same directory)")
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)
Expand Down Expand Up @@ -84,24 +74,23 @@ 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)
if err != nil {
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)
Expand Down
12 changes: 1 addition & 11 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `<html><body><form action="/demo/upload" method="post" enctype="multipart/form-data">
<input type="file" name="uploadfile"><br>
Expand All @@ -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")
Expand All @@ -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"}
}
Expand Down

0 comments on commit 96b290f

Please sign in to comment.