本文整理汇总了Golang中github.com/gotips/log.Debugf函数的典型用法代码示例。如果您正苦于以下问题:Golang Debugf函数的具体用法?Golang Debugf怎么用?Golang Debugf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Debugf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: execLevelExamples
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)
}
开发者ID:gotips,项目名称:log,代码行数:32,代码来源:level.go
示例2: RefreshAccessToken
// RefreshAccessToken 定时刷新 access_token
func RefreshAccessToken(appId, appSecret string) {
// 内部变量,外部不可以调用
var _token = &accessToken{}
AccessToken = func() string {
_token.mutex.RLock()
defer _token.mutex.RUnlock()
return _token.AccessToken
}
go func() {
url := fmt.Sprintf(tokenURL, appId, appSecret)
tick := time.Tick(refreshTimeout)
for {
new := refresh(url)
log.Debugf("old access token %+v", _token)
log.Debugf("new access token %+v", new)
_token.mutex.Lock()
_token.AccessToken = new.AccessToken
_token.ExpiresIn = new.ExpiresIn
_token.mutex.Unlock()
<-tick // 等待下一个时钟周期到来
}
}()
}
开发者ID:arstd,项目名称:weixin,代码行数:31,代码来源:accesstoken.go
示例3: echoMsgVoice
func echoMsgVoice(m *weixin.RecvVoice) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyVoice{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
MediaId: m.MediaId,
}
log.Debugf("%+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:14,代码来源:msghandler.go
示例4: EventDefaultHandler
// EventDefaultHandler 注册默认处理器
func EventDefaultHandler(m *weixin.Message) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Event=%s", m.Event),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:15,代码来源:eventhandler.go
示例5: echoMsgText
func echoMsgText(m *weixin.RecvText) weixin.ReplyMsg {
log.Debugf("receive message: %+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: m.FromUserName + ", " + m.Content,
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:14,代码来源:msghandler.go
示例6: echoMsgLocation
func echoMsgLocation(m *weixin.RecvLocation) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: weixin.AccessToken(),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:14,代码来源:msghandler.go
示例7: EventViewHandler
// EventViewHandler 注册点击菜单跳转链接时的事件处理器
func EventViewHandler(m *weixin.EventView) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message 貌似用户收不到回复的消息???
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Event=%s, EventKey=%s", m.Event, m.EventKey),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:15,代码来源:eventhandler.go
示例8: EventSubscribeHandler
// EventSubscribeHandler 注册关注事件处理器
func EventSubscribeHandler(m *weixin.EventSubscribe) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Event=%s, EventKey=%s, Ticket=%s", m.Event, m.EventKey, m.Ticket),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:15,代码来源:eventhandler.go
示例9: EventTemplateSendJobFinishHandler
// EventTemplateSendJobFinishHandler 模版消息发送结果通知事件
func EventTemplateSendJobFinishHandler(m *weixin.EventTemplateSendJobFinish) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Event=%s, MsgID=%d, Status=%s", m.Event, m.MsgID, m.Status),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:15,代码来源:eventhandler.go
示例10: echoMsgImage
func echoMsgImage(m *weixin.RecvImage) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyImage{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
PicUrl: m.PicUrl,
MediaId: m.MediaId,
}
log.Debugf("%+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:15,代码来源:msghandler.go
示例11: EventLocationHandler
// EventLocationHandler 注册上报地理位置事件处理器
func EventLocationHandler(m *weixin.EventLocation) weixin.ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &weixin.ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Latitude=%.6f, Longitude=%.6f, Precision=%.6f",
m.Latitude, m.Longitude, m.Precision),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:16,代码来源:eventhandler.go
示例12: echoMsgLink
func echoMsgLink(m *weixin.RecvLink) weixin.ReplyMsg {
log.Debugf("%+v", m)
// 回复图文消息
return nil
}
开发者ID:arstd,项目名称:weixin,代码行数:7,代码来源:msghandler.go
示例13: main
func main() {
addr := ":3080"
weixin.Initialize(originId, appId, appSecret, token, encodingAESKey)
weixin.RecvTextHandler = echoMsgText // 注册文本消息处理器
weixin.RecvImageHandler = echoMsgImage // 注册图片消息处理器
weixin.RecvVoiceHandler = echoMsgVoice // 注册语音消息处理器
weixin.RecvVideoHandler = echoMsgVideo // 注册视频消息处理器
weixin.RecvShortVideoHandler = echoMsgShortVideo // 注册小视频消息处理器
weixin.RecvLocationHandler = echoMsgLocation // 注册位置消息处理器
weixin.RecvLinkHandler = echoMsgLink // 注册链接消息处理器
weixin.RecvDefaultHandler = defaultHandler // 注册默认处理器
weixin.EventSubscribeHandler = EventSubscribeHandler // 注册关注事件处理器
weixin.EventUnsubscribeHandler = EventUnsubscribeHandler // 注册取消关注事件处理器
weixin.EventLocationHandler = EventLocationHandler // 注册上报地理位置事件处理器
weixin.EventClickHandler = EventClickHandler // 注册点击自定义菜单事件处理器
weixin.EventViewHandler = EventViewHandler // 注册点击菜单跳转链接时的事件处理器
// 模版消息发送结果通知事件
weixin.EventTemplateSendJobFinishHandler = EventTemplateSendJobFinishHandler
weixin.EventDefaultHandler = EventDefaultHandler // 注册默认处理器
http.HandleFunc("/weixin", weixin.HandleAccess)
http.Handle("/", http.FileServer(http.Dir("examples/static")))
// http.Handle("/admin/", http.StripPrefix("/admin/", http.FileServer(http.Dir("admin"))))
log.Debugf("server is running at %s", addr)
http.ListenAndServe(addr, nil)
}
开发者ID:arstd,项目名称:weixin,代码行数:30,代码来源:main.go
示例14: echoMsgShortVideo
func echoMsgShortVideo(m *weixin.RecvVideo) weixin.ReplyMsg {
log.Debugf("%+v", m)
// MediaId ???
ret := &weixin.ReplyVideo{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
MediaId: m.ThumbMediaId,
Title: "shortvideo",
Description: "thist is a test desc...",
}
log.Debugf("%+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:16,代码来源:msghandler.go
示例15: parseBody
func parseBody(encryptType, timestamp, nonce, msgSignature string, body []byte) (msg *Message, err error) {
msg = &Message{}
// 如果报文被加密了,先要验签解密
if encryptType == "aes" {
encMsg := &EncMessage{}
// 解析加密的 xml
err = xml.Unmarshal(body, encMsg)
if err != nil {
return nil, err
}
msg.ToUserName = encMsg.ToUserName
msg.Encrypt = encMsg.Encrypt
if !CheckSignature(Token, timestamp, nonce, encMsg.Encrypt, msgSignature) {
return nil, errors.New("check signature error")
}
body, err = DecryptMsg(encMsg.Encrypt, EncodingAESKey, AppId)
if err != nil {
return nil, err
}
log.Debugf("receive: %s", body)
}
// 解析 xml
err = xml.Unmarshal(body, msg)
if err != nil {
return nil, err
}
return msg, nil
}
开发者ID:arstd,项目名称:weixin,代码行数:32,代码来源:access.go
示例16: defaultHandler
func defaultHandler(msg *weixin.Message) weixin.ReplyMsg {
log.Debugf("%+v", msg)
event := weixin.NewRecvEvent(msg)
js, _ := json.Marshal(event)
// echo message
ret := &weixin.ReplyText{
ToUserName: msg.FromUserName,
FromUserName: msg.ToUserName,
CreateTime: msg.CreateTime,
Content: string(js),
}
log.Debugf("replay message: %+v", ret)
return ret
}
开发者ID:arstd,项目名称:weixin,代码行数:17,代码来源:msghandler.go
示例17: processMessage
// 处理所有来自微信的消息,已经验证过 URL 和 Method 了
func processMessage(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
timestamp := q.Get("timestamp")
nonce := q.Get("nonce")
encryptType := q.Get("encrypt_type")
msgSignature := q.Get("msg_signature")
// 读取报文
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Error(err)
http.Error(w, "read body error", http.StatusNotAcceptable)
return
}
log.Debugf("from weixin: %s", body)
msg, err := parseBody(encryptType, timestamp, nonce, msgSignature, body)
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// 处理消息
reply := HandleMessage(msg)
// 如果返回为 nil,表示不需要回复,结束
if reply == nil {
return
}
// 如果返回不为 nil,表示需要回复
ret, err := packReply(reply, encryptType, timestamp, nonce)
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
log.Debugf("to weixin: %s", ret)
w.Header().Set("Content-Type", "text/xml; charset=utf-8")
w.Write(ret)
}
开发者ID:arstd,项目名称:weixin,代码行数:44,代码来源:access.go
示例18: TestEventTemplateSendJobFinishHandler
func TestEventTemplateSendJobFinishHandler(t *testing.T) {
// EventTemplateSendJobFinishHandler 模版消息发送结果通知事件
EventTemplateSendJobFinishHandler = func(m *EventTemplateSendJobFinish) ReplyMsg {
log.Debugf("%+v", m)
// echo message
ret := &ReplyText{
ToUserName: m.FromUserName,
FromUserName: m.ToUserName,
CreateTime: m.CreateTime,
Content: fmt.Sprintf("Event=%s, MsgID=%d, Status=%s", m.Event, m.MsgID, m.Status),
}
log.Debugf("replay message: %+v", ret)
return ret
}
body := `<xml>
<ToUserName><![CDATA[gh_7f083739789a]]></ToUserName>
<FromUserName><![CDATA[oia2TjuEGTNoeX76QEjQNrcURxG8]]></FromUserName>
<CreateTime>1395658984</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[TEMPLATESENDJOBFINISH]]></Event>
<MsgID>200163840</MsgID>
<Status><![CDATA[failed: system failed]]></Status>
</xml>`
req, _ := http.NewRequest("POST", testURL, bytes.NewBufferString(body))
w := httptest.NewRecorder()
HandleAccess(w, req)
if w.Code != http.StatusOK {
t.Errorf("http request error with status %d: %s", w.Code, w.Body)
t.FailNow()
}
t.Logf("%s", w.Body)
}
开发者ID:arstd,项目名称:weixin,代码行数:38,代码来源:access_test.go
示例19: PostUnmarshal
// PostUnmarshal 工具类, POST json 并解析返回的报文,返回 error
func PostUnmarshal(url string, js []byte, ret interface{}) (err error) {
log.Debugf("url=%s, body=%s", url, js)
resp, err := http.Post(url, "application/json", bytes.NewBuffer(js))
if err != nil {
return err
}
defer resp.Body.Close()
err = json.NewDecoder(resp.Body).Decode(ret)
if err != nil {
return err
}
return nil
}
开发者ID:arstd,项目名称:weixin,代码行数:16,代码来源:httpclient.go
示例20: main
func main() {
log.Debugf("this is a test message, %d", 1111)
format := fmt.Sprintf("%s %s %s %s:%d %s", "2006-01-02 15:04:05.000000", log.TagToken,
log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Tinfof("6ba7b814-9dad-11d1-80b4-00c04fd430c8", "this is a test message, %d", 1111)
format = fmt.Sprintf(`{"date": "%s", "time": "%s", "level": "%s", "file": "%s", "line": %d, "log": "%s"}`,
"2006-01-02", "15:04:05.999", log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
format = fmt.Sprintf(`<log><date>%s</date><time>%s</time><level>%s</level><file>%s</file><line>%d</line><msg>%s</msg><log>`,
"2006-01-02", "15:04:05.000", log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Tinfof("6ba7b814-9dad-11d1-80b4-00c04fd430c8", "this is a test message, %d", 1111)
log.Error("level = debug")
log.Infof("this is a test message, %d", 1111)
log.Errorf("this is another test message, %d", 22222)
// Fatalf("%d %s", log.FatalLevel, log.FatalLevel)
format = fmt.Sprintf("%s %s %s %s:%d %s", "2006-1-2", "3:4:05.9",
log.LevelToken, log.PathToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
format = fmt.Sprintf("%s %s %s %s:%d %s", "2006-01-02", "15:04:05.999999",
log.LevelToken, log.PackageToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
format = fmt.Sprintf("%s %s %s:%d %s", "2006-01-02 15:04:05.000000",
log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
format = fmt.Sprintf(`{"date": "%s", "time": "%s", "level": "%s", "file": "%s", "line": %d, "log": "%s"}`,
"2006-01-02", "15:04:05.999", log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
format = fmt.Sprintf(`<log><date>%s</date><time>%s</time><level>%s</level><file>%s</file><line>%d</line><msg>%s</msg><log>`,
"2006-01-02", "15:04:05.000", log.LevelToken, log.ProjectToken, log.LineToken, log.MessageToken)
log.ChangeFormat(format)
log.Infof("this is a test message, %d", 1111)
}
开发者ID:CardInfoLink,项目名称:log,代码行数:48,代码来源:main.go
注:本文中的github.com/gotips/log.Debugf函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论