config: make log rotation configurable

This commit is contained in:
vegardengen
2018-04-07 00:11:42 +02:00
committed by Olaoluwa Osuntokun
parent 80d57f3ddf
commit 5eed171187
3 changed files with 32 additions and 21 deletions

4
log.go
View File

@@ -116,14 +116,14 @@ var subsystemLoggers = map[string]btclog.Logger{
// initLogRotator initializes the logging rotator to write logs to logFile and
// create roll files in the same directory. It must be called before the
// package-global log rotator variables are used.
func initLogRotator(logFile string) {
func initLogRotator(logFile string, MaxLogFileSize int, MaxLogFiles int) {
logDir, _ := filepath.Split(logFile)
err := os.MkdirAll(logDir, 0700)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create log directory: %v\n", err)
os.Exit(1)
}
r, err := rotator.New(logFile, 10*1024, false, 3)
r, err := rotator.New(logFile, int64(MaxLogFileSize*1024), false, MaxLogFiles)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create file rotator: %v\n", err)
os.Exit(1)