mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-04 13:16:43 +00:00
[NOD-994] Greatly increase the amount of logs kaspad keeps before rotating them away (#720)
* [NOD-994] Greatly increased the amount of logs kaspad keeps before rotating them away * [NOD-994] Actually invcrease the log file * [NOD-994] Update comments * [NOD-994] Fix typo
This commit is contained in:
parent
378f0b659a
commit
28681affda
@ -113,7 +113,7 @@ var subsystemLoggers = map[string]*logs.Logger{
|
||||
|
||||
// InitLog attaches log file and error log file to the backend log.
|
||||
func InitLog(logFile, errLogFile string) {
|
||||
err := BackendLog.AddLogFile(logFile, logs.LevelTrace)
|
||||
err := BackendLog.AddLogFileWithCustomRotator(logFile, logs.LevelTrace, 100*1024, 4)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, logs.LevelTrace, err)
|
||||
os.Exit(1)
|
||||
|
19
logs/logs.go
19
logs/logs.go
@ -35,7 +35,6 @@ package logs
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@ -44,6 +43,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/jrick/logrotate/rotator"
|
||||
)
|
||||
|
||||
@ -265,15 +266,27 @@ func callsite(flag uint32) (string, int) {
|
||||
return file, line
|
||||
}
|
||||
|
||||
const (
|
||||
defaultThresholdKB = 10 * 1024
|
||||
defaultMaxRolls = 3
|
||||
)
|
||||
|
||||
// AddLogFile adds a file which the log will write into on a certain
|
||||
// log level. It'll create the file if it doesn't exist.
|
||||
// log level with the default log rotation settings. It'll create the file if it doesn't exist.
|
||||
func (b *Backend) AddLogFile(logFile string, logLevel Level) error {
|
||||
return b.AddLogFileWithCustomRotator(logFile, logLevel, defaultThresholdKB, defaultMaxRolls)
|
||||
}
|
||||
|
||||
// AddLogFileWithCustomRotator adds a file which the log will write into on a certain
|
||||
// log level, with the specified log rotation settings.
|
||||
// It'll create the file if it doesn't exist.
|
||||
func (b *Backend) AddLogFileWithCustomRotator(logFile string, logLevel Level, thresholdKB int64, maxRolls int) error {
|
||||
logDir, _ := filepath.Split(logFile)
|
||||
err := os.MkdirAll(logDir, 0700)
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to create log directory: %s", err)
|
||||
}
|
||||
r, err := rotator.New(logFile, 10*1024, false, 3)
|
||||
r, err := rotator.New(logFile, thresholdKB, false, maxRolls)
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to create file rotator: %s", err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user