aboutsummaryrefslogtreecommitdiff
path: root/internal/tlog/log.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/tlog/log.go')
-rw-r--r--internal/tlog/log.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/internal/tlog/log.go b/internal/tlog/log.go
index 9277abd..9ebe535 100644
--- a/internal/tlog/log.go
+++ b/internal/tlog/log.go
@@ -57,22 +57,35 @@ type toggledLogger struct {
Logger *log.Logger
}
+// trimNewline removes one trailing newline from "msg"
+func trimNewline(msg string) string {
+ if len(msg) == 0 {
+ return msg
+ }
+ if msg[len(msg)-1] == '\n' {
+ return msg[:len(msg)-1]
+ }
+ return msg
+}
+
func (l *toggledLogger) Printf(format string, v ...interface{}) {
if !l.Enabled {
return
}
- l.Logger.Printf(l.prefix + fmt.Sprintf(format, v...) + l.postfix)
+ msg := trimNewline(fmt.Sprintf(format, v...))
+ l.Logger.Printf(l.prefix + msg + l.postfix)
if l.Wpanic {
- l.Logger.Panic(wpanicMsg + fmt.Sprintf(format, v...))
+ l.Logger.Panic(wpanicMsg + msg)
}
}
func (l *toggledLogger) Println(v ...interface{}) {
if !l.Enabled {
return
}
- l.Logger.Println(l.prefix + fmt.Sprint(v...) + l.postfix)
+ msg := trimNewline(fmt.Sprint(v...))
+ l.Logger.Println(l.prefix + msg + l.postfix)
if l.Wpanic {
- l.Logger.Panic(wpanicMsg + fmt.Sprint(v...))
+ l.Logger.Panic(wpanicMsg + msg)
}
}