From 490c82940a1fc6cf9d30c2fb2c65980c0d732654 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Tue, 6 Apr 2021 09:06:33 +0300 Subject: [PATCH] Removed dashed line between single-line log outputs --- src/logging/logging.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/logging/logging.go b/src/logging/logging.go index 910eac94..719db4a5 100644 --- a/src/logging/logging.go +++ b/src/logging/logging.go @@ -55,7 +55,8 @@ func With() zerolog.Context { } type PrettyZerologWriter struct { - wd string + wd string + wasLastLogMultiline bool } type PrettyLogEntry struct { @@ -86,7 +87,8 @@ var ColorFromLevel = map[string]string{ func NewPrettyZerologWriter() *PrettyZerologWriter { wd, _ := os.Getwd() return &PrettyZerologWriter{ - wd: wd, + wd: wd, + wasLastLogMultiline: false, } } @@ -124,8 +126,12 @@ func (w *PrettyZerologWriter) Write(p []byte) (int, error) { return strings.Compare(pretty.OtherFields[i].Name, pretty.OtherFields[j].Name) < 0 }) + isMultiline := (pretty.Error != "" || pretty.StackTrace != nil || pretty.OtherFields != nil) + var b strings.Builder - b.WriteString("---------------------------------------\n") + if isMultiline || w.wasLastLogMultiline { + b.WriteString("---------------------------------------\n") + } b.WriteString(pretty.Timestamp) b.WriteString(" ") if pretty.Level != "" { @@ -170,6 +176,8 @@ func (w *PrettyZerologWriter) Write(p []byte) (int, error) { } } + w.wasLastLogMultiline = isMultiline + return os.Stderr.Write([]byte(b.String())) }