// ParseTime 解析时间模板 func ParseTime(tmpl interface{}, data time.Time) string { tData := GetTimeData(data) buf, err := utils.NewParseTmpl(tmpl).Parse(tData) if err != nil { return "" } return buf.String() }
// ParseName 解析Name模板 func ParseName(tmpl interface{}, data *LogItem) string { fData := GetDateData(data.Time) fData["Level"] = data.Level.ToString() fData["Tag"] = data.Tag buf, err := utils.NewParseTmpl(tmpl).Parse(fData) if err != nil { return "" } return buf.String() }
// ParseLogItemWithBuffer 将日志项模板解析到缓冲区 func ParseLogItemToBuffer(tmpl interface{}, timeTmpl interface{}, data *LogItem) *bytes.Buffer { tData := GetTimeData(data.Time) timeBuf, err := utils.NewParseTmpl(timeTmpl).Parse(tData) if err != nil { return bytes.NewBufferString("") } lData := map[string]interface{}{ "ID": data.ID, "Time": timeBuf.String(), "Level": data.Level.ToString(), "Tag": data.Tag, "Message": data.Message, "FileName": data.File.Name, "FileFuncName": data.File.FuncName, "ShortName": data.File.ShortName, "FileLine": data.File.Line, } buf, err := utils.NewParseTmpl(tmpl).Parse(lData) if err != nil { return bytes.NewBufferString("") } return buf }