mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
In NATS Streaming, we have a test - started early on - that was testing logging and called SetLogger(l, true, true), then reset by calling SetLogger(l, false, false) to reset the values. That obviously had not the expected effect. During profiling, I noticed that there were tons of allocated objects due to NATS server debug/trace statements caused by that.
42 lines
1023 B
Go
42 lines
1023 B
Go
// Copyright 2014 Apcera Inc. All rights reserved.
|
|
|
|
package server
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestSetLogger(t *testing.T) {
|
|
server := &Server{}
|
|
dl := &DummyLogger{}
|
|
server.SetLogger(dl, true, true)
|
|
|
|
// We assert that the logger has change to the DummyLogger
|
|
_ = log.logger.(*DummyLogger)
|
|
|
|
if debug != 1 {
|
|
t.Fatalf("Expected debug 1, received value %d\n", debug)
|
|
}
|
|
|
|
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{}
|
|
|
|
func (l *DummyLogger) Noticef(format string, v ...interface{}) {}
|
|
func (l *DummyLogger) Errorf(format string, v ...interface{}) {}
|
|
func (l *DummyLogger) Fatalf(format string, v ...interface{}) {}
|
|
func (l *DummyLogger) Debugf(format string, v ...interface{}) {}
|
|
func (l *DummyLogger) Tracef(format string, v ...interface{}) {}
|