Skip to content

Commit

Permalink
Add debug and trace logging switches
Browse files Browse the repository at this point in the history
Add arguments to get more verbose logging...
Previously we had to recompile the binary with different log levels...
  • Loading branch information
mulbc committed Nov 8, 2019
1 parent dd89951 commit 188262a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
11 changes: 10 additions & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand All @@ -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 {
Expand Down

0 comments on commit 188262a

Please sign in to comment.