mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-12 01:13:10 -06:00
Fix conditional in format function
This commit is contained in:
parent
d31f6fbcc2
commit
b10cf01ae4
|
|
@ -32,38 +32,34 @@ type dendriteFormatter struct {
|
||||||
func (f dendriteFormatter) Format(entry *logrus.Entry) (format []byte, err error) {
|
func (f dendriteFormatter) Format(entry *logrus.Entry) (format []byte, err error) {
|
||||||
entry.Time = entry.Time.UTC()
|
entry.Time = entry.Time.UTC()
|
||||||
|
|
||||||
if _, ok := entry.Data["prefix"]; ok {
|
prefix, ok := entry.Data["prefix"].(string)
|
||||||
prefix, ok := entry.Data["prefix"].(string)
|
if !ok {
|
||||||
if !ok {
|
return f.TextFormatter.Format(entry)
|
||||||
return f.TextFormatter.Format(entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
prefix = strings.ToUpper(prefix)
|
|
||||||
|
|
||||||
if !f.TextFormatter.DisableColors {
|
|
||||||
prefix = ansi.Color(prefix, "white+b")
|
|
||||||
}
|
|
||||||
|
|
||||||
entry.Message = fmt.Sprintf("%s: %s\t", prefix, entry.Message)
|
|
||||||
|
|
||||||
// Generate the formatted log without the prefix as a field
|
|
||||||
// Use a copy of the entry so the same entry isn't altered by multiple
|
|
||||||
// fields at the same time
|
|
||||||
entryCpy := *entry
|
|
||||||
// Go doesn't perform deep copies, so the fields have to be manually
|
|
||||||
// copied
|
|
||||||
fields := make(logrus.Fields)
|
|
||||||
for k, v := range entry.Data {
|
|
||||||
if k != "prefix" {
|
|
||||||
fields[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entryCpy.Data = fields
|
|
||||||
format, err = f.TextFormatter.Format(&entryCpy)
|
|
||||||
} else {
|
|
||||||
format, err = f.TextFormatter.Format(entry)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix = strings.ToUpper(prefix)
|
||||||
|
|
||||||
|
if !f.TextFormatter.DisableColors {
|
||||||
|
prefix = ansi.Color(prefix, "white+b")
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.Message = fmt.Sprintf("%s: %s\t", prefix, entry.Message)
|
||||||
|
|
||||||
|
// Generate the formatted log without the prefix as a field
|
||||||
|
// Use a copy of the entry so the same entry isn't altered by multiple
|
||||||
|
// fields at the same time
|
||||||
|
entryCpy := *entry
|
||||||
|
// Go doesn't perform deep copies, so the fields have to be manually
|
||||||
|
// copied
|
||||||
|
fields := make(logrus.Fields)
|
||||||
|
for k, v := range entry.Data {
|
||||||
|
if k != "prefix" {
|
||||||
|
fields[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entryCpy.Data = fields
|
||||||
|
format, err = f.TextFormatter.Format(&entryCpy)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue