3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

align log messages with space padding

This commit is contained in:
Shivaram Lingamneni 2020-04-12 13:30:52 -04:00
parent 6e4b0b3125
commit dbbcd800c9

View File

@ -43,7 +43,7 @@ var (
LogLevelDisplayNames = map[Level]string{ LogLevelDisplayNames = map[Level]string{
LogDebug: "debug", LogDebug: "debug",
LogInfo: "info", LogInfo: "info",
LogWarning: "warning", LogWarning: "warn",
LogError: "error", LogError: "error",
} }
) )
@ -227,7 +227,9 @@ func (logger *singleLogger) Log(level Level, logType string, messageParts ...str
// assemble full line // assemble full line
var rawBuf bytes.Buffer var rawBuf bytes.Buffer
fmt.Fprintf(&rawBuf, "%s : %s : %s : ", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), LogLevelDisplayNames[level], logType) // XXX magic number here: 9 is len("listeners"), the longest log category name
// in current use. it's not a big deal if this number gets out of date.
fmt.Fprintf(&rawBuf, "%s : %-5s : %-9s : ", time.Now().UTC().Format("2006-01-02T15:04:05.000Z"), LogLevelDisplayNames[level], logType)
for i, p := range messageParts { for i, p := range messageParts {
rawBuf.WriteString(p) rawBuf.WriteString(p)