fehlerbehebung

This commit is contained in:
xoy 2023-01-29 16:09:39 +01:00
parent b2ee161247
commit 992f39a475
3 changed files with 28 additions and 7 deletions

26
file.go
View File

@ -29,9 +29,31 @@ func fileAddLine(input string, filepath string) {
}
func fileCreate(filepath string) {
if !fileExist(filepath) {
_, err := os.Create(filepath)
errorPanic(err)
logger("file created -> " + filepath)
logger("fileCreate : file created -> " + filepath)
} else {
logger("fileCreate : file already exists -> " + filepath)
}
}
func fileCreateDir(dirpath string) {
if fileExist(dirpath) {
err := os.Mkdir(dirpath, 0755)
errorPanic(err)
logger("fileCreateDir : folder created -> " + dirpath)
} else {
logger("fileCreateDir : folder not created -> " + dirpath)
}
}
func fileExist(filepath string) bool {
if _, err := os.Stat(filepath); err == nil {
return true
} else if errors.Is(err, os.ErrNotExist) {
return false
}
return false
}

View File

@ -3,6 +3,7 @@ package main
import "time"
func logger(input string) {
fileCreateDir("./log")
println("[" + time.Now().Format("15:04:05") + "] " + input)
fileAddLine("["+time.Now().Format("15:04:05")+"] "+input, "./log/"+time.Now().Format("2006-02-01")+".log")
}
@ -13,6 +14,6 @@ func errorPanic(err error, logBefore ...string) {
logger(log)
}
logger(err.Error())
panic("----------------ERROR----------------")
panic("\n----------------ERROR----------------\n")
}
}

View File

@ -23,8 +23,6 @@ func main() {
err := http.ListenAndServe(addr, nil)
errorPanic(err)
defer logger("----------------END----------------")
}
func handler() {