Closed Script47 closed 1 year ago
I did something like this, making a service for logging and then calling this throughout my project.
package loggy
import (
"github.com/charmbracelet/log"
"os"
)
type Logger struct {
*log.Logger
}
func New() *Logger {
return &Logger{log.NewWithOptions(os.Stdout, log.Options{
ReportCaller: true,
ReportTimestamp: true,
})}
}
func (log *Logger) Fatal(args ...interface{}) {
file, err := os.OpenFile("logfile.txt", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
log.Fatal(err)
}
log.SetReportCaller(true)
log.SetOutput(file)
log.Fatal(args)
file.Close().Error()
}
Hope this was helpful.
@JustJordanT
Definitely helpful, thanks.
I hadn't even considered making a wrapper around it.
Is it possible to toggle
ReportCaller
onFatal
/Fatalf
andError
/Errorf
calls but not the remaining calls?