Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: support maxBackups in config.toml #2186

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

zlacfzy
Copy link
Contributor

@zlacfzy zlacfzy commented Jan 26, 2024

Description

Add maxBackups in config.toml.
MaxBackups means the log file that would be retained, by default it would be 0, which means there is no limitation.
If set MaxBackups = 240, only logs of the most recent 240 hours(10 days) would be kept, since the default rotate time is 1 hour.
See more: #2165.

Rationale

Add a MaxBackups in Node.LogConfig.

[Node.LogConfig]
FileRoot = ""
FilePath = "bsc.log"
MaxBytesSize = 10485760
Level = "info"

Example

[Node.LogConfig]
FileRoot = ""
FilePath = "bsc.log"
MaxBytesSize = 10485760
Level = "info"
MaxBackups = 240

Changes

Notable changes:

  • log: add maxBackups in config.toml

@zlacfzy zlacfzy changed the base branch from master to develop January 26, 2024 06:16
node/node.go Show resolved Hide resolved
buddh0
buddh0 previously approved these changes Jan 29, 2024
@zzzckck
Copy link
Collaborator

zzzckck commented Jan 29, 2024

I would prefer: remove the specified 1 log file on rotateFile()
like:

func (w *AsyncFileWriter) rotateFile() {
	select {
	case <-w.timeTicker.C:
		if err := w.flushAndClose(); err != nil {
			fmt.Fprintf(os.Stderr, "flush and close file error. err=%s", err)
		}
		if err := w.initLogFile(); err != nil {
			fmt.Fprintf(os.Stderr, "init log file error. err=%s", err)
		}
                // start from here
                if maxBackups > 0 {
		   if err := w.removeExpiredFile(); err != nil {
			fmt.Fprintf(os.Stderr, "remove expired file error. err=%s", err)
		   }
                }
                // end
	default:
	}
}

log/async_file_writer.go Outdated Show resolved Hide resolved
log/async_file_writer.go Outdated Show resolved Hide resolved
@zzzckck zzzckck merged commit 82beb2c into bnb-chain:develop Jan 30, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants