Skip to content

Commit

Permalink
Add Verbose to Config and remove Debug variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Jun 5, 2016
1 parent b1db4a6 commit e46a81a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ type Config struct {
// Service is the name of the service being offered if a Handler exists.
Service string `json:"service,omitempty"`

// Verbose enables logging of underlying Gyre/Zyre messages when set to true.
Verbose bool `json:"verbose,omitempty"`

// Version is the optional version string of the service being offered.
Version string `json:"version,omitempty"`

Expand Down
15 changes: 7 additions & 8 deletions sleuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
"github.com/zeromq/gyre"
)

// Debug enables logging of underlying Gyre/Zyre messages when set to true.
var Debug = false

var (
group = "SLEUTH-v0"
port = 5670
Expand All @@ -35,6 +32,7 @@ type connection struct {
node string
port int
server bool
verbose bool
version string
}

Expand Down Expand Up @@ -81,6 +79,11 @@ func newNode(log *logger.Logger, conn *connection) (*gyre.Gyre, error) {
if err != nil {
return nil, newError(errInitialize, err.Error())
}
if conn.verbose {
if err := node.SetVerbose(); err != nil {
return nil, newError(errVerbose, err.Error())
}
}
if err := node.SetPort(conn.port); err != nil {
return nil, newError(errPort, err.Error())
}
Expand All @@ -89,11 +92,6 @@ func newNode(log *logger.Logger, conn *connection) (*gyre.Gyre, error) {
return nil, newError(errInterface, err.Error())
}
}
if Debug {
if err := node.SetVerbose(); err != nil {
return nil, newError(errVerbose, err.Error())
}
}
// If announcing a service, add service headers.
if conn.server {
errors := [...]int{
Expand Down Expand Up @@ -133,6 +131,7 @@ func New(config *Config) (*Client, error) {
// is guaranteed to be correct in initConfig, errors can be ignored.
log, _ := logger.New(config.logLevel)
conn := new(connection)
conn.verbose = config.Verbose
if conn.server = config.Handler != nil; conn.server {
conn.handler = config.Handler
conn.name = config.Service
Expand Down
3 changes: 1 addition & 2 deletions sleuth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,8 @@ func TestBadLogLevelInConfig(t *testing.T) {
}

func TestBadServerInstantiation(t *testing.T) {
Debug = true
defer func() { Debug = false }()
_, err := New(&Config{
Verbose: true,
Handler: new(silentHandler),
Service: "sleuth-test-server-four",
Port: 1})
Expand Down

0 comments on commit e46a81a

Please sign in to comment.