Reputation: 19
I have a script to print the same log like:
type Country stuct{
cityName string
}
var c Country
and I
var logger = logrus.New()
logger.Debug(c)
but in the log file, it looks like:
country_name:\"\\347\\276\\216\\345\\233\\275\"
I want to know what \\347\\276\\216\\345\\233\\275\
means and how to read the true meanwhile my script read the log file.
Upvotes: 1
Views: 366
Reputation: 19
func convertOctonaryUtf8(in string) string {
s := []byte(in)
reg := regexp.MustCompile(`\\[0-7]{3}`)
out := reg.ReplaceAllFunc(s,
func(b []byte) []byte {
i, _ := strconv.ParseInt(string(b[1:]), 8, 0)
return []byte{byte(i)}
})
return string(out)
}
the func get the "\347\276\216\345\233\275\" mean
Upvotes: 0
Reputation: 49231
The default logrus formatter writes JSON with ASCII encoding. You need to implement your own formatter and use UTF-8. See Logger.SetFormatter.
As I looked into the source code I didn't see any setting that can be set to change the encoding.
Upvotes: 3