Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将json string格式化以后多出来的 %!(EXTRAstring= 该如何解决 #45

Open
lyb124553153 opened this issue Apr 23, 2016 · 0 comments

Comments

@lyb124553153
Copy link

在user.go里面给增加user写了一个日志
引入了

import (
    m "github.com/beego/admin/src/models"
    "github.com/astaxie/beego/logs"
    "encoding/json"
)
func (this *UserController) AddUser() {
    log := logs.NewLogger(10000)
    log.SetLogger("file", `{"filename":"user.log"}`)
    u := m.User{}
    uinfo,_ := json.Marshal(u)

    if err := this.ParseForm(&u); err != nil {
        //handle error
        this.Rsp(false, err.Error())
        return
    }
    id, err := m.AddUser(&u)
    if err == nil && id > 0 {
        log.Info("加入用户",string(uinfo))
        this.Rsp(true, "Success")
        return
    } else {
        this.Rsp(false, err.Error())
        return
    }
       log.Close()
}

之后生成的日志格式为
2016/04/23 16:09:59 [I] 加入用户%!(EXTRA string=`{"Id":0,"Username":"","Password":"","Repassword":"","Nickname":"","Email":"","Remark":"","Status":0,"Lastlogintime":"0001-01-01T00:00:00Z","Createtime":"0001-01-01T00:00:00Z","Role":null})
为何生成的日志 会有 %!(EXTRAstring='的字样 如果把这个多余的部分 去掉 球解

@lyb124553153 lyb124553153 changed the title 如果把json数组写入日志 将json string格式化以后多出来的 %!(EXTRAstring= 该如何解决 Apr 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant