diff --git a/nzx_tmpmail/loggingshit/log.go b/nzx_tmpmail/loggingshit/log.go index 8d71827..2dcc73e 100644 --- a/nzx_tmpmail/loggingshit/log.go +++ b/nzx_tmpmail/loggingshit/log.go @@ -6,42 +6,31 @@ import ( "os" ) -var l log.Logger +var l *log.Logger -/* -1: default -2: error -3: critical error -*/ -func Log(shit string, lvl int, typeshi ...any) { +const ( + lerr = 2 + lcrit = 3 +) +func Log(msg string, lvl int, args ...any) { switch lvl { + case lerr: + l.Printf("[err] "+msg, args...) + case lcrit: + l.Panicf("[critical] "+msg, args...) default: - l.Printf(shit, typeshi...) - case 2: - l.Printf("[err] "+shit, typeshi...) - case 3: - l.Panic(shit) + l.Printf(msg, args...) } } func init() { - var fl *os.File - - _, err := os.Stat("logs") + fl, err := os.OpenFile("app.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) if err != nil { - fl, err = os.Create("logs") - if err != nil { - panic("couldn't create log file") - } - } else { - fl, err = os.OpenFile("logs", os.O_APPEND, os.ModeAppend) - if err != nil { - panic("couldn't open log file, even tho it exists") - } + panic("couldn't open log file: " + err.Error()) } mw := io.MultiWriter(os.Stdout, fl) - l = *log.New(mw, "[nzx_tmpmail] ", log.LUTC|log.Ldate|log.Ltime) + l = log.New(mw, "[nzx_tmpmail] ", log.LUTC|log.Ldate|log.Ltime) }