예제 #1
0
파일: level.go 프로젝트: gotips/log
func execLevelExamples() {
	// 默认日志级别 debug
	log.Printf("default log level: %s", log.GetLevel())
	log.Tracef("IsTraceEnabled? %t", log.IsTraceEnabled())
	log.Debugf("IsDebugEnabled? %t", log.IsDebugEnabled())
	log.Infof("IsInfoEnabled? %t", log.IsInfoEnabled())

	// trace 级别
	log.SetLevel(log.Ltrace)
	log.Tracef(msgFmt, 1)

	// info 级别
	log.SetLevel(log.Linfo)
	log.Debugf(msgFmt, 2)
	log.Infof(msgFmt, 2)

	// warn 级别
	log.SetLevel(log.Lwarn)
	log.Infof(msgFmt, 3)
	log.Warnf(msgFmt, 3)

	// error 级别
	log.SetLevel(log.Lerror)
	log.Warnf(msgFmt, 4)
	log.Errorf(msgFmt, 4)

	// 恢复默认级别,防止影响其他测试
	// debug 级别
	log.SetLevel(log.Ldebug)
	log.Tracef(msgFmt, 5)
	log.Debugf(msgFmt, 5)
}
예제 #2
0
파일: color.go 프로젝트: gotips/log
func execColorizedExamples() {
	log.SetLevel(log.Lall)
	log.Info("default config")

	log.Colorized(true)
	log.Info("colorized config")

	log.Colorized(false)
	log.Error("close colorized config")
}
예제 #3
0
func TestDecryptMsg(t *testing.T) {
	log.SetLevel(log.TraceLevel)

	appId := "wxfabf18ec7ccd2d1a"
	aesKey, _ := base64.StdEncoding.DecodeString("0t37dWsIYg6NsVLgEY1fNuB1rSLyyeQEHOAlIfMhQUV=")

	b64Enc := "Z8JufHXESFt4chL0Q6vusyowhizt4mpo9Zn3DkyomP7vVhFKi3ICTa1yCOs2XjSl1BaDkKUWl0lQf7psDRwJtP+YD/I6l+TCw0DrRQQyOY9Lf/4FKQ9cpBN+TyhZErDtDJN2E6Euw8VjtV0FmSqH3dGj4sPmWmEiRLldM0luY1WjW1tKGGB2x5vWwFC4piADCw5v9uPYvRk3gZCeknPHmCkCg8ERhi89J7yUuALHwheCo38+4WdQ+YCVVoj7vzZypRiytdwWxvga8OmOk3H99WJdcKQxO7UsgKtpdV/m4rhl3S+iA0HvSOXgQd3v+lAvS8eXsejFUQj92hUP+tV1wKxdg0jK1vxT1Mww0O77N5hIA38atfMMSo8IjVV+HleLbFZ3ByCiyNxrrGDh8ljqFNyVwcJJcz9ZZAnu3XOf+BQ="

	// AES CBC 解密报文
	src, err := DecryptMsg(b64Enc, aesKey, appId)
	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	t.Logf("%s", src)
}
예제 #4
0
func TestEncryptMsg(t *testing.T) {
	log.SetLevel(log.TraceLevel)

	appId := "wxfabf18ec7ccd2d1a"
	aesKey, _ := base64.StdEncoding.DecodeString("0t37dWsIYg6NsVLgEY1fNuB1rSLyyeQEHOAlIfMhQUV=")

	msg := `<xml><ToUserName><![CDATA[gh_274da2028f77]]></ToUserName>
<FromUserName><![CDATA[ozmLcjnM7vnrXmb3DimFLi0EOiY8]]></FromUserName>
<CreateTime>1448604897</CreateTime>
<MsgType><![CDATA[text]]></MsgType>
<Content><![CDATA[sts]]></Content>
<MsgId>6221710657841833060</MsgId>
</xml>`

	// AES CBC 加密报文
	b64Enc, err := EncryptMsg([]byte(msg), aesKey, appId)
	if err != nil {
		t.Log(err)
		t.FailNow()
	}

	t.Logf("%s", b64Enc)
}