Skip to content

Commit

Permalink
Merge pull request nats-io#360 from nats-io/fix_setlogger
Browse files Browse the repository at this point in the history
[FIXED] SetLogger to be able to set debug/trace to 0
  • Loading branch information
derekcollison authored Oct 6, 2016
2 parents 8caed5e + 9f758bb commit 8da901f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion server/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ type Logger interface {
func (s *Server) SetLogger(logger Logger, debugFlag, traceFlag bool) {
if debugFlag {
atomic.StoreInt32(&debug, 1)
} else {
atomic.StoreInt32(&debug, 0)
}

if traceFlag {
atomic.StoreInt32(&trace, 1)
} else {
atomic.StoreInt32(&trace, 0)
}

log.Lock()
Expand Down
12 changes: 11 additions & 1 deletion server/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (

func TestSetLogger(t *testing.T) {
server := &Server{}
server.SetLogger(&DummyLogger{}, true, true)
dl := &DummyLogger{}
server.SetLogger(dl, true, true)

// We assert that the logger has change to the DummyLogger
_ = log.logger.(*DummyLogger)
Expand All @@ -20,6 +21,15 @@ func TestSetLogger(t *testing.T) {
if trace != 1 {
t.Fatalf("Expected trace 1, received value %d\n", trace)
}

// Make sure that we can reset to fal
server.SetLogger(dl, false, false)
if debug != 0 {
t.Fatalf("Expected debug 0, got %v", debug)
}
if trace != 0 {
t.Fatalf("Expected trace 0, got %v", trace)
}
}

type DummyLogger struct{}
Expand Down

0 comments on commit 8da901f

Please sign in to comment.