chore: refactor logx (#2262)

master
Kevin Wan 2 years ago committed by GitHub
parent 9af1a42386
commit 05dd6bd743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -307,16 +307,17 @@ func writePlainAny(writer io.Writer, level string, val interface{}, fields ...st
case fmt.Stringer:
writePlainText(writer, level, v.String(), fields...)
default:
writePlainValue(writer, level, v, fields...)
}
}
func writePlainText(writer io.Writer, level, msg string, fields ...string) {
var buf strings.Builder
buf.WriteString(getTimestamp())
buf.WriteByte(plainEncodingSep)
buf.WriteString(level)
buf.WriteByte(plainEncodingSep)
if err := json.NewEncoder(&buf).Encode(val); err != nil {
log.Println(err.Error())
return
}
buf.WriteString(msg)
for _, item := range fields {
buf.WriteByte(plainEncodingSep)
buf.WriteString(item)
@ -331,15 +332,18 @@ func writePlainAny(writer io.Writer, level string, val interface{}, fields ...st
log.Println(err.Error())
}
}
}
func writePlainText(writer io.Writer, level, msg string, fields ...string) {
func writePlainValue(writer io.Writer, level string, val interface{}, fields ...string) {
var buf strings.Builder
buf.WriteString(getTimestamp())
buf.WriteByte(plainEncodingSep)
buf.WriteString(level)
buf.WriteByte(plainEncodingSep)
buf.WriteString(msg)
if err := json.NewEncoder(&buf).Encode(val); err != nil {
log.Println(err.Error())
return
}
for _, item := range fields {
buf.WriteByte(plainEncodingSep)
buf.WriteString(item)

Loading…
Cancel
Save