fehlerbehebung
This commit is contained in:
parent
b2ee161247
commit
992f39a475
30
file.go
30
file.go
|
@ -29,9 +29,31 @@ func fileAddLine(input string, filepath string) {
|
|||
}
|
||||
|
||||
func fileCreate(filepath string) {
|
||||
_, err := os.Create(filepath)
|
||||
if !fileExist(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"
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue