diff --git a/src/github.com/matrix-org/dendrite/common/log.go b/src/github.com/matrix-org/dendrite/common/log.go index 66948396c..ebf49f46b 100644 --- a/src/github.com/matrix-org/dendrite/common/log.go +++ b/src/github.com/matrix-org/dendrite/common/log.go @@ -32,38 +32,34 @@ type dendriteFormatter struct { func (f dendriteFormatter) Format(entry *logrus.Entry) (format []byte, err error) { entry.Time = entry.Time.UTC() - if _, ok := entry.Data["prefix"]; ok { - prefix, ok := entry.Data["prefix"].(string) - if !ok { - 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, ok := entry.Data["prefix"].(string) + if !ok { + 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) + return }