package logger import ( "fmt" "runtime/debug" "strings" "time" ) type Logger interface { Info(message string) Infof(format string, a ...any) Warning(message string) Critical(message string) Fatal(message string) } type ML struct { } func (m *ML) sendMsg(message string) { // Da die CSV Dateien RFC3339 nutzen, wechsel ich darauf im Log der // Konsistenz wegen. msg := "# " + time.Now().Format(time.RFC3339) + "\n* " + message fmt.Println(msg) } func (m *ML) sendMsgWithStack(message string) { msg := message stack := string(debug.Stack()) msg += "\n\n### *** Stack ***\n\n\n >" + indentStacktrace(stack) msg += "\n________" m.sendMsg(msg) } func (m *ML) Info(message string) { m.sendMsgWithStack("Info: " + message) } func (m *ML) Infof(format string, a ...any) { msg := fmt.Sprintf(format, a) m.sendMsgWithStack("Info: " + msg) } func (m *ML) Warning(message string) { m.sendMsgWithStack("Warning: " + message) } func (m *ML) Critical(message string) { stack := string(debug.Stack()) m.sendMsgWithStack("Critical: " + message + indentStacktrace(stack)) } func (m *ML) Fatal(message string) { m.sendMsgWithStack("Fatal" + message) panic(message) } func indentStacktrace(stack string) string { lines := strings.Split(stack, "\n") for i := 1; i < len(lines); i++ { lines[i] = " " + lines[i] } return strings.Join(lines, "\n") } func NewMarcoLogger() Logger { log := ML{} return &log }