Updates before synching with new host-repo.

This commit is contained in:
2023-10-02 14:34:16 -04:00
parent 4f0ac4a452
commit db5da9bb48
5 changed files with 114 additions and 0 deletions

46
logger.go Normal file
View File

@@ -0,0 +1,46 @@
package main
import (
"fmt"
"log"
"os"
)
type Logger struct {
logpath string
logfile []byte
}
// write to our file, if it exists
func (l *Logger) Log(str string) {
CheckLogPath(l.logpath)
var msg string
msg = str
os.WriteFile(l.logpath, []byte(msg), os.ModeAppend)
}
// dump the err into a string, write to our log file, then pass off the error to the log package
func (l *Logger) Fatal(err error) {
l.Log(fmt.Sprintf("%v\n", err))
log.Fatal(err)
}
func NewLogger(logpath string) *Logger {
CheckLogPath(logpath)
return &Logger{
logpath: logpath,
}
}
// checks for existence of given logpath file, creates if it doesn't
func CheckLogPath(logpath string) {
_, err := os.Stat(logpath)
if os.IsNotExist(err) {
os.Create(logpath)
} else if err != nil {
log.Fatal(err)
}
}