2015-10-13 16:27:29 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2015-11-03 19:24:29 +00:00
|
|
|
"bytes"
|
2015-11-28 22:13:45 +00:00
|
|
|
"log"
|
2015-10-13 16:27:29 +00:00
|
|
|
"testing"
|
|
|
|
|
2016-01-18 11:24:33 +00:00
|
|
|
"github.com/v2ray/v2ray-core/common/serial"
|
2016-03-24 15:36:06 +00:00
|
|
|
"github.com/v2ray/v2ray-core/common/platform"
|
2015-12-02 14:27:18 +00:00
|
|
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2015-10-13 16:27:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLogLevelSetting(t *testing.T) {
|
2015-12-02 14:27:18 +00:00
|
|
|
v2testing.Current(t)
|
2015-10-13 16:27:29 +00:00
|
|
|
|
|
|
|
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 19:24:29 +00:00
|
|
|
|
|
|
|
func TestStreamLogger(t *testing.T) {
|
2015-12-02 14:27:18 +00:00
|
|
|
v2testing.Current(t)
|
2015-11-03 19:24:29 +00:00
|
|
|
|
|
|
|
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
|
2015-12-05 20:10:14 +00:00
|
|
|
infoLogger = &stdOutLogWriter{
|
2015-11-28 22:13:45 +00:00
|
|
|
logger: log.New(buffer, "", 0),
|
2015-11-03 19:24:29 +00:00
|
|
|
}
|
2016-01-18 11:24:33 +00:00
|
|
|
Info("Test ", "Stream Logger", " Format")
|
2016-03-24 15:36:06 +00:00
|
|
|
assert.StringLiteral(string(buffer.Bytes())).Equals("[Info]Test Stream Logger Format" + platform.LineSeparator())
|
2015-11-03 19:30:14 +00:00
|
|
|
|
|
|
|
buffer.Reset()
|
2015-12-05 20:10:14 +00:00
|
|
|
errorLogger = infoLogger
|
2016-01-18 11:24:33 +00:00
|
|
|
Error("Test ", serial.StringLiteral("literal"), " Format")
|
2016-03-24 15:36:06 +00:00
|
|
|
assert.StringLiteral(string(buffer.Bytes())).Equals("[Error]Test literal Format" + platform.LineSeparator())
|
2015-11-03 19:24:29 +00:00
|
|
|
}
|