Turning off debug mode for tests because it's too verbose. Making sure LevelLogger is initialized correctly under all scenarios.
This commit is contained in:
parent
2f88701c9c
commit
1535c74b02
3 changed files with 17 additions and 9 deletions
|
@ -33,6 +33,10 @@ type LevelLogger struct {
|
||||||
debug bool
|
debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *LevelLogger) EnableDebug(enable bool) {
|
||||||
|
l.debug = enable
|
||||||
|
}
|
||||||
|
|
||||||
func (l LevelLogger) DebugPrintf(format string, a ...interface{}) {
|
func (l LevelLogger) DebugPrintf(format string, a ...interface{}) {
|
||||||
if l.debug {
|
if l.debug {
|
||||||
l.Print("[DEBUG] ")
|
l.Print("[DEBUG] ")
|
||||||
|
|
19
realis.go
19
realis.go
|
@ -96,7 +96,7 @@ type RealisConfig struct {
|
||||||
backoff Backoff
|
backoff Backoff
|
||||||
transport thrift.TTransport
|
transport thrift.TTransport
|
||||||
protoFactory thrift.TProtocolFactory
|
protoFactory thrift.TProtocolFactory
|
||||||
logger Logger
|
logger *LevelLogger
|
||||||
InsecureSkipVerify bool
|
InsecureSkipVerify bool
|
||||||
certspath string
|
certspath string
|
||||||
clientkey, clientcert string
|
clientkey, clientcert string
|
||||||
|
@ -207,7 +207,7 @@ func ZookeeperOptions(opts ...ZKOpt) ClientOption {
|
||||||
// Using the word set to avoid name collision with Interface.
|
// Using the word set to avoid name collision with Interface.
|
||||||
func SetLogger(l Logger) ClientOption {
|
func SetLogger(l Logger) ClientOption {
|
||||||
return func(config *RealisConfig) {
|
return func(config *RealisConfig) {
|
||||||
config.logger = l
|
config.logger = &LevelLogger{l, false}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ func NewRealisClient(options ...ClientOption) (Realis, error) {
|
||||||
// Default configs
|
// Default configs
|
||||||
config.timeoutms = 10000
|
config.timeoutms = 10000
|
||||||
config.backoff = defaultBackoff
|
config.backoff = defaultBackoff
|
||||||
config.logger = log.New(os.Stdout, "realis: ", log.Ltime|log.Ldate|log.LUTC)
|
config.logger = &LevelLogger{log.New(os.Stdout, "realis: ", log.Ltime|log.Ldate|log.LUTC), false}
|
||||||
|
|
||||||
// Save options to recreate client if a connection error happens
|
// Save options to recreate client if a connection error happens
|
||||||
config.options = options
|
config.options = options
|
||||||
|
@ -259,18 +259,23 @@ func NewRealisClient(options ...ClientOption) (Realis, error) {
|
||||||
opt(config)
|
opt(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(rdelvalle): Move this logic to it's own function to make initialization code easier to read.
|
||||||
|
|
||||||
// Turn off all logging (including debug)
|
// Turn off all logging (including debug)
|
||||||
if config.logger == nil {
|
if config.logger == nil {
|
||||||
config.logger = LevelLogger{NoopLogger{}, false}
|
config.logger = &LevelLogger{NoopLogger{}, false}
|
||||||
}
|
}
|
||||||
|
|
||||||
config.logger.Println("Number of options applied to config: ", len(options))
|
|
||||||
|
|
||||||
// Set a logger if debug has been set to true but no logger has been set
|
// Set a logger if debug has been set to true but no logger has been set
|
||||||
if config.logger == nil && config.debug {
|
if config.logger == nil && config.debug {
|
||||||
config.logger = log.New(os.Stdout, "realis: ", log.Ltime|log.Ldate|log.LUTC)
|
config.logger = &LevelLogger{log.New(os.Stdout, "realis: ", log.Ltime|log.Ldate|log.LUTC), true}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note, by this point, a LevelLogger should have been created.
|
||||||
|
config.logger.EnableDebug(config.debug)
|
||||||
|
|
||||||
|
config.logger.DebugPrintln("Number of options applied to config: ", len(options))
|
||||||
|
|
||||||
//Set default Transport to JSON if needed.
|
//Set default Transport to JSON if needed.
|
||||||
if !config.jsonTransport && !config.binTransport {
|
if !config.jsonTransport && !config.binTransport {
|
||||||
config.jsonTransport = true
|
config.jsonTransport = true
|
||||||
|
|
|
@ -40,8 +40,7 @@ func TestMain(m *testing.M) {
|
||||||
// New configuration to connect to Vagrant image
|
// New configuration to connect to Vagrant image
|
||||||
r, err = realis.NewRealisClient(realis.SchedulerUrl("http://192.168.33.7:8081"),
|
r, err = realis.NewRealisClient(realis.SchedulerUrl("http://192.168.33.7:8081"),
|
||||||
realis.BasicAuth("aurora", "secret"),
|
realis.BasicAuth("aurora", "secret"),
|
||||||
realis.TimeoutMS(20000),
|
realis.TimeoutMS(20000))
|
||||||
realis.Debug())
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Please run vagrant box before running test suite")
|
fmt.Println("Please run vagrant box before running test suite")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue