Show log on log.Fatal calls, provide "sanitized" version, fix goreleaser

Sanitization means change anything in double quotes to "CENSORED". A
notice is included telling the user to check for themselves as well.
This commit is contained in:
Harvey Tindall
2021-06-11 23:28:21 +01:00
parent f0f4e8118e
commit b538922c05
13 changed files with 2015 additions and 64 deletions
+14 -1
View File
@@ -2,6 +2,7 @@
package logger
import (
"errors"
"io"
"log"
"runtime"
@@ -16,12 +17,14 @@ type Logger interface {
Println(v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
SetFatalFunc(f func(err interface{}))
}
type logger struct {
logger *log.Logger
shortfile bool
printer *c.Color
fatalFunc func(err interface{})
}
func Lshortfile() string {
@@ -97,7 +100,16 @@ func (l logger) Fatalf(format string, v ...interface{}) {
out = Lshortfile()
}
out += " " + l.printer.Sprintf(format, v...)
l.logger.Fatal(out)
if l.fatalFunc != nil {
l.logger.Print(out)
l.fatalFunc(errors.New(out))
} else {
l.logger.Fatal(out)
}
}
func (l logger) SetFatalFunc(f func(err interface{})) {
l.fatalFunc = f
}
type EmptyLogger bool
@@ -107,3 +119,4 @@ func (l EmptyLogger) Print(v ...interface{}) {}
func (l EmptyLogger) Println(v ...interface{}) {}
func (l EmptyLogger) Fatal(v ...interface{}) {}
func (l EmptyLogger) Fatalf(format string, v ...interface{}) {}
func (l EmptyLogger) SetFatalFunc(f func(err interface{})) {}