feat(logging): add weekly log rotation and retention

This commit is contained in:
2026-09-30 20:43:04 +01:00
parent bd15b054dd
commit 8a5325414b
5 changed files with 720 additions and 6 deletions
+10 -5
View File
@@ -2,17 +2,22 @@ package logging
import (
"fmt"
"io"
"os"
"path/filepath"
"time"
log "github.com/sirupsen/logrus"
)
// setupLogging ensures log directory, opens log file, and configures logrus.
// Returns the *os.File so caller can defer its Close().
func SetupLogging(logDir, serviceName, buildVersion string) (*os.File, error) {
fileName := logDir + serviceName + ".log"
f, err := os.OpenFile(fileName, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
// SetupLogging ensures the log directory, opens the rotating log writer, and configures logrus.
func SetupLogging(logDir, serviceName, buildVersion string) (io.WriteCloser, error) {
if err := os.MkdirAll(logDir, 0o755); err != nil {
return nil, fmt.Errorf("create log directory: %w", err)
}
fileName := filepath.Join(logDir, serviceName+".log")
f, err := newWeeklyLogWriter(fileName, time.Local, defaultWeeklyLogRuntime())
if err != nil {
return nil, fmt.Errorf("open log file: %w", err)
}