标签:cname 去除 code select def tac sprintf fun level
//输出日志到console
msg := fmt.Sprintf(format, args...) //format里的坑 args解出的数据相匹配
fmt.Fprintf(os.Stdout, "%s\n", msg)
//输出日志到文件
file, _ := os.OpenFile("/tmp/test.log", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0755)
fmt.Fprintf(file, "name: %s\n", "maotai")
//将日志写入chan
select {
case f.LogDataChan <- logData:
default:
}
//从chan中去除日志写到文件
for logData := range f.LogDataChan {
fmt.Fprintf(file, "%s %s (%s:%s:%d) %s\n", logData.TimeStr, logData.LevelStr, logData.Filename, logData.FuncName, logData.LineNo, logData.Message)
}
标签:cname 去除 code select def tac sprintf fun level
原文地址:https://www.cnblogs.com/iiiiiher/p/12005041.html