From 67a6961b4bda497be33b969e9da3ad704cb9b624 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 29 Jun 2015 13:34:29 +0100 Subject: [PATCH] Adjust logrus feature of padding all lines less than 44 chars with spaces at the end --- common/logging.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/common/logging.go b/common/logging.go index cd3deaa5..9c971d09 100644 --- a/common/logging.go +++ b/common/logging.go @@ -21,9 +21,14 @@ func (f *textFormatter) Format(entry *logrus.Entry) ([]byte, error) { levelText := strings.ToUpper(entry.Level.String())[0:4] timeStamp := entry.Time.Format("2006/01/02 15:04:05.000000") - fmt.Fprintf(b, "%s: %s %-44s ", levelText, timeStamp, entry.Message) - for k, v := range entry.Data { - fmt.Fprintf(b, " %s=%v", k, v) + if len(entry.Data) > 0 { + fmt.Fprintf(b, "%s: %s %-44s ", levelText, timeStamp, entry.Message) + for k, v := range entry.Data { + fmt.Fprintf(b, " %s=%v", k, v) + } + } else { + // No padding when there's no fields + fmt.Fprintf(b, "%s: %s %s", levelText, timeStamp, entry.Message) } b.WriteByte('\n')