1
0
Fork 0

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.

This commit is contained in:
Alexander Andreev 2023-05-25 02:25:43 +04:00
parent fccb81d3a5
commit afbaad971a
Signed by: Arav
GPG Key ID: D22A817D95815393
1 changed files with 6 additions and 8 deletions

View File

@ -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 {