logging shit
This commit is contained in:
47
nzx_tmpmail/loggingshit/log.go
Normal file
47
nzx_tmpmail/loggingshit/log.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package loggingshit
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var l log.Logger
|
||||
|
||||
/*
|
||||
1: default
|
||||
2: error
|
||||
3: critical error
|
||||
*/
|
||||
func Log(shit string, lvl int, typeshi ...any) {
|
||||
|
||||
switch lvl {
|
||||
default:
|
||||
l.Printf(shit, typeshi...)
|
||||
case 2:
|
||||
l.Printf("[err] "+shit, typeshi...)
|
||||
case 3:
|
||||
l.Panic(shit)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
var fl *os.File
|
||||
|
||||
_, err := os.Stat("logs")
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
mw := io.MultiWriter(os.Stdout, fl)
|
||||
|
||||
l = *log.New(mw, "[nzx_tmpmail] ", log.LUTC|log.Ldate|log.Ltime)
|
||||
}
|
||||
Reference in New Issue
Block a user