2017-12-10 16:48:28 -05:00
|
|
|
package log_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"v2ray.com/core/common/log"
|
|
|
|
"v2ray.com/core/common/net"
|
|
|
|
. "v2ray.com/ext/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testLogger struct {
|
|
|
|
value string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *testLogger) Handle(msg log.Message) {
|
|
|
|
l.value = msg.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLogRecord(t *testing.T) {
|
|
|
|
assert := With(t)
|
|
|
|
|
|
|
|
var logger testLogger
|
|
|
|
log.RegisterHandler(&logger)
|
|
|
|
|
|
|
|
ip := "8.8.8.8"
|
|
|
|
log.Record(&log.GeneralMessage{
|
|
|
|
Severity: log.Severity_Error,
|
|
|
|
Content: net.ParseAddress(ip),
|
|
|
|
})
|
|
|
|
|
2018-02-22 09:28:21 -05:00
|
|
|
assert(logger.value, Equals, "[Error] "+ip)
|
2017-12-10 16:48:28 -05:00
|
|
|
}
|