Skip to content

Commit

Permalink
x-cray#24 Fix double space in log line with empty message
Browse files Browse the repository at this point in the history
  • Loading branch information
LuVx21 committed Mar 13, 2024
1 parent 8914074 commit cb3576e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,27 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *logrus.Entry, keys
}

if f.DisableTimestamp {
fmt.Fprintf(b, "%s"+ prefixFormat + " " + messageFormat, level, prefix, message)
if message == "" {
fmt.Fprintf(b, "%s"+ prefixFormat, level, prefix)
} else {
fmt.Fprintf(b, "%s"+ prefixFormat + " " + messageFormat, level, prefix, message)
}
} else {
var timestamp string
if !f.FullTimestamp {
timestamp = fmt.Sprintf("[%04d]", miniTS())
} else {
timestamp = fmt.Sprintf("[%s]", entry.Time.Format(timestampFormat))
}
fmt.Fprintf(b, "%s %s" + prefixFormat + " " + messageFormat, colorScheme.TimestampColor(timestamp), level, prefix, message)

coloredTimestamp := colorScheme.TimestampColor(timestamp)
if message == "" {
fmt.Fprintf(b, "%s %s" + prefixFormat, coloredTimestamp, level, prefix)
} else {
fmt.Fprintf(b, "%s %s" + prefixFormat + " " + messageFormat, coloredTimestamp, level, prefix, message)
}
}

for _, k := range keys {
if k != "prefix" {
v := entry.Data[k]
Expand Down

0 comments on commit cb3576e

Please sign in to comment.