Files
arbeitszeitmessung/Backend/helper/logs/main.go
Tom Tröger b4bf550863
Some checks failed
Tests / Run Go Tests (push) Failing after 59s
fix: closing some issues from sonarqube
2026-02-15 18:49:29 +01:00

28 lines
613 B
Go

// Helper package to create audit logs in the logs folder
// these are by the time only generated, when a booking is
// changed on the /time page
package logs
import (
"log"
"os"
"time"
)
type FileLog struct {
Logger *log.Logger
Close func() error
}
var Logs map[string]FileLog = make(map[string]FileLog)
func NewAudit() (i *log.Logger, close func() error) {
logName := "logs/" + time.Now().Format(time.DateOnly) + ".log"
logFile, err := os.OpenFile(logName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Panic(err)
}
return log.New(logFile, "", log.LstdFlags), logFile.Close
}