create a logger interface and use it everywhere

This commit is contained in:
Marten Seemann 2018-03-28 07:30:36 +07:00
parent 1e9b3f0bb2
commit 948eef3e42
52 changed files with 411 additions and 281 deletions

View file

@ -19,12 +19,14 @@ func main() {
flag.Parse()
urls := flag.Args()
logger := utils.DefaultLogger
if *verbose {
utils.SetLogLevel(utils.LogLevelDebug)
logger.SetLogLevel(utils.LogLevelDebug)
} else {
utils.SetLogLevel(utils.LogLevelInfo)
logger.SetLogLevel(utils.LogLevelInfo)
}
utils.SetLogTimeFormat("")
logger.SetLogTimeFormat("")
versions := protocol.SupportedVersions
if *tls {
@ -42,21 +44,21 @@ func main() {
var wg sync.WaitGroup
wg.Add(len(urls))
for _, addr := range urls {
utils.Infof("GET %s", addr)
logger.Infof("GET %s", addr)
go func(addr string) {
rsp, err := hclient.Get(addr)
if err != nil {
panic(err)
}
utils.Infof("Got response for %s: %#v", addr, rsp)
logger.Infof("Got response for %s: %#v", addr, rsp)
body := &bytes.Buffer{}
_, err = io.Copy(body, rsp.Body)
if err != nil {
panic(err)
}
utils.Infof("Request Body:")
utils.Infof("%s", body.Bytes())
logger.Infof("Request Body:")
logger.Infof("%s", body.Bytes())
wg.Done()
}(addr)
}