mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Change log sizes and add some new features to logger (#1400)
* Increase default log sizes, and increase kaspad log sizes * Add an option to not print logs to stdout * Allow logs to be printed in the current working directory * Add more pruning related logs * Add comment and increase log rotations to save last 64 logs
This commit is contained in:
parent
53744ceb45
commit
c1361e5b3e
@ -171,6 +171,7 @@ func (pm *pruningManager) UpdatePruningPointByVirtual() error {
|
||||
}
|
||||
|
||||
if !newCandidate.Equal(currentCandidate) {
|
||||
log.Debugf("Staged a new pruning candidate, old: %s, new: %s", currentCandidate, newCandidate)
|
||||
pm.pruningStore.StagePruningPointCandidate(newCandidate)
|
||||
}
|
||||
|
||||
@ -181,6 +182,7 @@ func (pm *pruningManager) UpdatePruningPointByVirtual() error {
|
||||
}
|
||||
|
||||
if !newPruningPoint.Equal(currentPruningPoint) {
|
||||
log.Debugf("Moving pruning point from %s to %s", currentPruningPoint, newPruningPoint)
|
||||
err = pm.savePruningPoint(newPruningPoint)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -447,6 +449,8 @@ func (pm *pruningManager) validateUTXOSetFitsCommitment(
|
||||
pruningPointHash, utxoSetHash, expectedUTXOCommitment)
|
||||
}
|
||||
|
||||
log.Debugf("Validated the pruning point %s UTXO commitment: %s", pruningPointHash, utxoSetHash)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -159,8 +159,8 @@ var subsystemLoggers = map[string]*Logger{
|
||||
|
||||
// InitLog attaches log file and error log file to the backend log.
|
||||
func InitLog(logFile, errLogFile string) {
|
||||
// 250 MB (MB=1000^2 bytes)
|
||||
err := BackendLog.AddLogFileWithCustomRotator(logFile, LevelTrace, 1000*250, 32)
|
||||
// 280 MB (MB=1000^2 bytes)
|
||||
err := BackendLog.AddLogFileWithCustomRotator(logFile, LevelTrace, 1000*280, 64)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error adding log file %s as log rotator for level %s: %s", logFile, LevelTrace, err)
|
||||
os.Exit(1)
|
||||
|
@ -129,7 +129,7 @@ func (l Level) String() string {
|
||||
|
||||
// NewBackend creates a new logger backend.
|
||||
func NewBackend(opts ...BackendOption) *Backend {
|
||||
b := &Backend{flag: defaultFlags}
|
||||
b := &Backend{flag: defaultFlags, toStdout: true}
|
||||
for _, o := range opts {
|
||||
o(b)
|
||||
}
|
||||
@ -148,6 +148,7 @@ type Backend struct {
|
||||
rotators []*backendLogRotator
|
||||
mu sync.Mutex // ensures atomic writes
|
||||
flag uint32
|
||||
toStdout bool
|
||||
}
|
||||
|
||||
// BackendOption is a function used to modify the behavior of a Backend.
|
||||
@ -266,8 +267,8 @@ func callsite(flag uint32) (string, int) {
|
||||
}
|
||||
|
||||
const (
|
||||
defaultThresholdKB = 10 * 1024
|
||||
defaultMaxRolls = 3
|
||||
defaultThresholdKB = 100 * 1000 // 100 MB logs by default.
|
||||
defaultMaxRolls = 8 // keep 8 last logs by default.
|
||||
)
|
||||
|
||||
// AddLogFile adds a file which the log will write into on a certain
|
||||
@ -281,9 +282,12 @@ func (b *Backend) AddLogFile(logFile string, logLevel Level) error {
|
||||
// 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)
|
||||
// if the logDir is empty then `logFile` is in the cwd and there's no need to create any directory.
|
||||
if logDir != "" {
|
||||
err := os.MkdirAll(logDir, 0700)
|
||||
if err != nil {
|
||||
return errors.Errorf("failed to create log directory: %+v", err)
|
||||
}
|
||||
}
|
||||
r, err := rotator.New(logFile, thresholdKB, false, maxRolls)
|
||||
if err != nil {
|
||||
@ -348,7 +352,10 @@ func (b *Backend) printf(lvl Level, tag string, format string, args ...interface
|
||||
func (b *Backend) write(lvl Level, bytesToWrite []byte) {
|
||||
b.mu.Lock()
|
||||
defer b.mu.Unlock()
|
||||
os.Stdout.Write(bytesToWrite)
|
||||
if b.toStdout {
|
||||
os.Stdout.Write(bytesToWrite)
|
||||
}
|
||||
|
||||
for _, r := range b.rotators {
|
||||
if lvl >= r.logLevel {
|
||||
r.Write(bytesToWrite)
|
||||
@ -363,6 +370,11 @@ func (b *Backend) Close() {
|
||||
}
|
||||
}
|
||||
|
||||
// WriteToStdout sets if the backend will print to stdout or not (default: true)
|
||||
func (b *Backend) WriteToStdout(stdout bool) {
|
||||
b.toStdout = stdout
|
||||
}
|
||||
|
||||
// Logger returns a new logger for a particular subsystem that writes to the
|
||||
// Backend b. A tag describes the subsystem and is included in all log
|
||||
// messages. The logger uses the info verbosity level by default.
|
||||
|
Loading…
x
Reference in New Issue
Block a user