2015-10-13 12:27:29 -04:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2015-11-03 14:24:29 -05:00
|
|
|
"bytes"
|
2015-10-13 12:27:29 -04:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/testing/unit"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLogLevelSetting(t *testing.T) {
|
|
|
|
assert := unit.Assert(t)
|
|
|
|
|
|
|
|
assert.Pointer(debugLogger).Equals(noOpLoggerInstance)
|
|
|
|
SetLogLevel(DebugLevel)
|
|
|
|
assert.Pointer(debugLogger).Equals(streamLoggerInstance)
|
|
|
|
|
|
|
|
SetLogLevel(InfoLevel)
|
|
|
|
assert.Pointer(debugLogger).Equals(noOpLoggerInstance)
|
|
|
|
assert.Pointer(infoLogger).Equals(streamLoggerInstance)
|
|
|
|
}
|
2015-11-03 14:24:29 -05:00
|
|
|
|
|
|
|
func TestStreamLogger(t *testing.T) {
|
|
|
|
assert := unit.Assert(t)
|
|
|
|
|
|
|
|
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
|
|
|
|
logger := &streamLogger{
|
|
|
|
writer: buffer,
|
|
|
|
}
|
|
|
|
logger.WriteLog("TestPrefix: ", "Test %s Format", "Stream Logger")
|
|
|
|
assert.Bytes(buffer.Bytes()).Equals([]byte("TestPrefix: Test Stream Logger Format\n"))
|
|
|
|
}
|