logging shit
This commit is contained in:
3
nzx_tmpmail/go.mod
Normal file
3
nzx_tmpmail/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module git.uwushka.cc/nzx056/nzx056/nzx_tmpmail
|
||||||
|
|
||||||
|
go 1.25.4
|
||||||
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)
|
||||||
|
}
|
||||||
0
nzx_tmpmail/logs
Normal file
0
nzx_tmpmail/logs
Normal file
5
nzx_tmpmail/main.go
Normal file
5
nzx_tmpmail/main.go
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user