Added ability to disable level text truncation. Fixes #406

This commit is contained in:
Tony Lee 2016-08-31 23:54:59 +10:00
parent 3ec0642a7f
commit 7a1f601cfd
1 changed files with 7 additions and 1 deletions

View File

@ -54,6 +54,9 @@ type TextFormatter struct {
// that log extremely frequently and don't use the JSON formatter this may not
// be desired.
DisableSorting bool
// Disables the truncation of the level text to 4 characters.
DisableLevelTruncation bool
}
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
@ -113,7 +116,10 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
levelColor = blue
}
levelText := strings.ToUpper(entry.Level.String())[0:4]
levelText := strings.ToUpper(entry.Level.String())
if !f.DisableLevelTruncation {
levelText = levelText[0:4]
}
if !f.FullTimestamp {
fmt.Fprintf(b, "\x1b[%dm%s\x1b[0m[%04d] %-44s ", levelColor, levelText, miniTS(), entry.Message)