Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ColorHeaderAndFields logger option #118

Merged
merged 7 commits into from Aug 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 18 additions & 5 deletions intlogger.go
Expand Up @@ -32,6 +32,10 @@ const TimeFormatJSON = "2006-01-02T15:04:05.000000Z07:00"
// errJsonUnsupportedTypeMsg is included in log json entries, if an arg cannot be serialized to json
const errJsonUnsupportedTypeMsg = "logging contained values that don't serialize to json"

// multiLinePrefix is used for fields that contain multi-line values
// when using non-JSON logging.
const multiLinePrefix = " | "

var (
_levelToBracket = map[Level]string{
Debug: "[DEBUG]",
Expand Down Expand Up @@ -401,22 +405,31 @@ func (l *intLogger) logPlain(t time.Time, name string, level Level, msg string,
if strings.Contains(val, "\n") {
l.writer.WriteString("\n ")
l.writer.WriteString(key)
l.writer.WriteString("=\n")
if l.fieldColor != ColorOff {
writeIndent(l.writer, val, faintColor.Sprint(" | "))
l.writer.WriteString(faintColor.Sprint("=\n"))
writeIndent(l.writer, val, faintColor.Sprint(multiLinePrefix))
picatz marked this conversation as resolved.
Show resolved Hide resolved
} else {
writeIndent(l.writer, val, " | ")
l.writer.WriteString("=\n")
writeIndent(l.writer, val, multiLinePrefix)
}
l.writer.WriteString(" ")
} else if !raw && needsQuoting(val) {
l.writer.WriteByte(' ')
l.writer.WriteString(key)
l.writer.WriteByte('=')
if l.fieldColor != ColorOff {
l.writer.WriteString(faintColor.Sprint("="))
} else {
l.writer.WriteByte('=')
}
l.writer.WriteString(strconv.Quote(val))
} else {
l.writer.WriteByte(' ')
l.writer.WriteString(key)
l.writer.WriteByte('=')
if l.fieldColor != ColorOff {
l.writer.WriteString(faintColor.Sprint("="))
} else {
l.writer.WriteByte('=')
}
l.writer.WriteString(val)
}
}
Expand Down