fehlerbehebung
This commit is contained in:
parent
b2ee161247
commit
992f39a475
26
file.go
26
file.go
|
@ -29,9 +29,31 @@ func fileAddLine(input string, filepath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileCreate(filepath string) {
|
func fileCreate(filepath string) {
|
||||||
|
if !fileExist(filepath) {
|
||||||
_, err := os.Create(filepath)
|
_, err := os.Create(filepath)
|
||||||
|
|
||||||
errorPanic(err)
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
func logger(input string) {
|
func logger(input string) {
|
||||||
|
fileCreateDir("./log")
|
||||||
println("[" + time.Now().Format("15:04:05") + "] " + input)
|
println("[" + time.Now().Format("15:04:05") + "] " + input)
|
||||||
fileAddLine("["+time.Now().Format("15:04:05")+"] "+input, "./log/"+time.Now().Format("2006-02-01")+".log")
|
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(log)
|
||||||
}
|
}
|
||||||
logger(err.Error())
|
logger(err.Error())
|
||||||
panic("----------------ERROR----------------")
|
panic("\n----------------ERROR----------------\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue