I have this function which I use to log:
func formattedLog(prefix, m string, color int) {
fmt.Printf("\033[%dm%s", color, DateTimeFormat)
fmt.Printf("▶ %s: %s\033[%dm
", prefix, m, int(Black))
}
I want to save my log output in some file:
f, err := os.OpenFile("../../../go-logs.txt", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatal("error opening logs file", err)
}
defer f.Close()
//set output of logs to f
log.SetOutput(f)
log.Println("This is a test log entry") // <====This logs in file
but when I call my function, which uses fmt.Printf it doesn't log in the file go-logs.txt
:
formattedErr("ERR", msg, err.Error(), int(Red))
is there anyway to setoutput also for fmt.Printf