custom formatter extended
This commit is contained in:
parent
ccf93660b5
commit
97274e2b9d
1 changed files with 12 additions and 2 deletions
|
|
@ -52,11 +52,21 @@ func (f *CustomFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||||
errVal = fmt.Sprintf("%v\n", errVal)
|
errVal = fmt.Sprintf("%v\n", errVal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fieldsLine := "| params: "
|
||||||
|
fields := entry.Data
|
||||||
|
if fields != nil {
|
||||||
|
for key, val := range fields {
|
||||||
|
fieldsLine += fmt.Sprintf("\t%v=%v ", key, val)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fieldsLine = "\n"
|
||||||
|
}
|
||||||
|
|
||||||
cyanCode := f.getLevelColor(logrus.TraceLevel)
|
cyanCode := f.getLevelColor(logrus.TraceLevel)
|
||||||
filename := fmt.Sprintf("%s[%s:%d]%s", cyanCode, file, line, resetCode)
|
filename := fmt.Sprintf("%s[%s:%d]%s", cyanCode, file, line, resetCode)
|
||||||
|
|
||||||
logLine := fmt.Sprintf("%s[%s]%v %s\t%v",
|
logLine := fmt.Sprintf("%s[%s]%v %s\t%v %v",
|
||||||
coloredLevel, timestamp, filename, msg, errVal)
|
coloredLevel, timestamp, filename, msg, fieldsLine, errVal)
|
||||||
|
|
||||||
return []byte(logLine), nil
|
return []byte(logLine), nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue