Skip to content

log: support maxBackups in config.toml#2186

Merged
zzzckck merged 3 commits intobnb-chain:developfrom
zlacfzy:add_log_maxbackup
Jan 30, 2024
Merged

log: support maxBackups in config.toml#2186
zzzckck merged 3 commits intobnb-chain:developfrom
zlacfzy:add_log_maxbackup

Conversation

@zlacfzy
Copy link
Copy Markdown
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
buddh0
buddh0 previously approved these changes Jan 29, 2024
@zzzckck
Copy link
Copy Markdown
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:
	}
}

@zzzckck zzzckck merged commit 82beb2c into bnb-chain:develop Jan 30, 2024
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