From afbaad971ac0c71b0737dc39821edce0e34dc555 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 25 May 2023 02:25:43 +0400 Subject: [PATCH] Instantiate log file handle and an instance of log.Logger. Also remove reopen SIGHUP handler. Log file will be truncated with logrotate instead of recreating. --- cmd/dwelling-upload/main.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/dwelling-upload/main.go b/cmd/dwelling-upload/main.go index 8a83e0d..48b1372 100644 --- a/cmd/dwelling-upload/main.go +++ b/cmd/dwelling-upload/main.go @@ -2,7 +2,6 @@ package main import ( "dwelling-upload/internal/http" - "dwelling-upload/pkg/logging" "dwelling-upload/pkg/utils" "dwelling-upload/pkg/watcher" "flag" @@ -60,11 +59,14 @@ func main() { } logFilePath := path.Join(os.Getenv("LOGS_DIRECTORY"), "file.log") - logFile, err := logging.New(logFilePath) + + logFileFd, err := os.OpenFile(logFilePath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0660) if err != nil { - log.Fatalln("file logger:", err) + log.Fatalln("failed to open file.log:", err) } - defer logFile.Close() + defer logFileFd.Close() + + logFile := log.New(logFileFd, "", log.LstdFlags) watcha, err := watcher.NewInotifyWatcher() if err != nil { @@ -108,14 +110,10 @@ func main() { doneSignal := make(chan os.Signal, 1) signal.Notify(doneSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM) - logReopenSignal := make(chan os.Signal, 1) - signal.Notify(logReopenSignal, syscall.SIGHUP) go func() { for { select { - case <-logReopenSignal: - logFile.Reopen(logFilePath) case <-uploadDirNotify: uploadDirSize, err = utils.DirectorySize(*uploadDir) if err != nil {