From ff51f6867bce2d7a48663d874f1c2b359264b98b Mon Sep 17 00:00:00 2001 From: MirageTurtle <60972592+MirageTurtle@users.noreply.github.com> Date: Wed, 7 Aug 2024 10:40:58 +0800 Subject: [PATCH] Format error message, use `log.Fatalf` for panic message of `Mkdir` --- src/main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.go b/src/main.go index 58ad23d..472785a 100644 --- a/src/main.go +++ b/src/main.go @@ -131,7 +131,7 @@ func (r *RadiusCredentials) accountingCron(accessLogger, errorLogger *log.Logger } }) if err != nil { - log.Fatalf("[ERR] Add accounting cron job: %s", err) + log.Fatalf("[ERR] Failed to add accounting cron job: %s", err) } c.Start() return c @@ -157,7 +157,7 @@ func init() { gantedLogDir := getEnv("GANTED_LOG_DIR", "/var/log/ganted") if _, err := os.Stat(gantedLogDir); os.IsNotExist(err) { if err := os.Mkdir(gantedLogDir, 0755); err != nil { - panic(err) + log.Fatalf("[ERR] Failed to create ganted log directory %s: %s", gantedLogDir, err) } } } @@ -168,7 +168,7 @@ func setFileLoggerOutput(logger *log.Logger, filePath string) error { } file, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o644) if err != nil { - log.Fatalf("[ERR] Open log file: %s", err) + log.Fatalf("[ERR] Failed to open file %s: %s", filePath, err) } prevWriter := logger.Writer() logger.SetOutput(file)