From 188262a477af29b90ea12a599bce08b40b99eb17 Mon Sep 17 00:00:00 2001 From: Chris Blum Date: Fri, 8 Nov 2019 16:37:31 +0100 Subject: [PATCH] Add debug and trace logging switches Add arguments to get more verbose logging... Previously we had to recompile the binary with different log levels... --- Readme.md | 2 ++ server/main.go | 11 ++++++++++- worker/main.go | 12 +++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index f8a7481..6633ce3 100644 --- a/Readme.md +++ b/Readme.md @@ -10,6 +10,8 @@ Gosbench consists of two parts: * Server: Coordinates Workers and general test queue * Workers: Actually connect to S3 and perform reading, writing, deleting and listing of objects +INFO: `-d` activates debug logging, `-t` activates trace logging + ### Running a test 1. Build the server: `go install github.com/mulbc/gosbench/server` diff --git a/server/main.go b/server/main.go index 47d7121..a900510 100644 --- a/server/main.go +++ b/server/main.go @@ -17,22 +17,31 @@ import ( ) func init() { - log.SetLevel(log.InfoLevel) log.SetFormatter(&log.TextFormatter{ FullTimestamp: true, }) rand.Seed(time.Now().UnixNano()) flag.StringVar(&configFileLocation, "c", "", "Config file describing test run") + flag.BoolVar(&debug, "d", false, "enable debug log output") + flag.BoolVar(&trace, "t", false, "enable trace log output") flag.Parse() // Only demand this flag if we are not running go test if configFileLocation == "" && flag.Lookup("test.v") == nil { log.Fatal("-c is a mandatory parameter - please specify the config file") } + if debug { + log.SetLevel(log.DebugLevel) + } else if trace { + log.SetLevel(log.TraceLevel) + } else { + log.SetLevel(log.InfoLevel) + } } var configFileLocation string var readyWorkers chan *net.Conn +var debug, trace bool func loadConfigFromFile(configFileContent []byte) common.Testconf { var config common.Testconf diff --git a/worker/main.go b/worker/main.go index 9167c91..59d5117 100644 --- a/worker/main.go +++ b/worker/main.go @@ -14,9 +14,9 @@ import ( ) var config common.WorkerConf +var debug, trace bool func init() { - log.SetLevel(log.InfoLevel) log.SetFormatter(&log.TextFormatter{ FullTimestamp: true, }) @@ -26,11 +26,21 @@ func init() { func main() { var serverAddress string flag.StringVar(&serverAddress, "s", "", "Gosbench Server IP and Port in the form '192.168.1.1:2000'") + flag.BoolVar(&debug, "d", false, "enable debug log output") + flag.BoolVar(&trace, "t", false, "enable trace log output") flag.Parse() if serverAddress == "" { log.Fatal("-s is a mandatory parameter - please specify the server IP and Port") } + if debug { + log.SetLevel(log.DebugLevel) + } else if trace { + log.SetLevel(log.TraceLevel) + } else { + log.SetLevel(log.InfoLevel) + } + for { err := connectToServer(serverAddress) if err != nil {