new logger and etcd fixes

This commit is contained in:
ston1th 2021-10-09 16:52:06 +02:00
commit cbd4f38cca
11 changed files with 248 additions and 161 deletions

View file

@ -1,13 +1,19 @@
package util
import (
"errors"
"fmt"
"net/http"
"runtime"
"k8s.io/klog/v2"
"github.com/iand/logfmtr"
)
var reallyCrash = true
var (
reallyCrash = true
log = logfmtr.New()
panicErr = errors.New("observed a panic")
)
func HandleCrash() {
if r := recover(); r != nil {
@ -34,8 +40,8 @@ func logPanic(r interface{}) {
stacktrace := make([]byte, size)
stacktrace = stacktrace[:runtime.Stack(stacktrace, false)]
if _, ok := r.(string); ok {
klog.Errorf("Observed a panic: %s\n%s", r, stacktrace)
log.Error(panicErr, fmt.Sprintf("%s\n%s", r, stacktrace))
} else {
klog.Errorf("Observed a panic: %#v (%v)\n%s", r, r, stacktrace)
log.Error(panicErr, fmt.Sprintf("%#v (%v)\n%s", r, r, stacktrace))
}
}