1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-12 15:27:16 -05:00
v2fly/common/log/log_test.go

39 lines
937 B
Go
Raw Normal View History

package log
import (
2015-11-03 14:24:29 -05:00
"bytes"
2015-11-28 17:13:45 -05:00
"log"
"testing"
v2testing "github.com/v2ray/v2ray-core/testing"
"github.com/v2ray/v2ray-core/testing/assert"
)
func TestLogLevelSetting(t *testing.T) {
v2testing.Current(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) {
v2testing.Current(t)
2015-11-03 14:24:29 -05:00
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
2015-12-05 15:10:14 -05:00
infoLogger = &stdOutLogWriter{
2015-11-28 17:13:45 -05:00
logger: log.New(buffer, "", 0),
2015-11-03 14:24:29 -05:00
}
2015-12-05 15:10:14 -05:00
Info("Test %s Format", "Stream Logger")
assert.Bytes(buffer.Bytes()).Equals([]byte("[Info]Test Stream Logger Format\n"))
2015-11-03 14:30:14 -05:00
buffer.Reset()
2015-12-05 15:10:14 -05:00
errorLogger = infoLogger
Error("Test No Format")
assert.Bytes(buffer.Bytes()).Equals([]byte("[Error]Test No Format\n"))
2015-11-03 14:24:29 -05:00
}