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

Add logfile_max_num feature #4548

Merged
merged 2 commits into from Sep 18, 2023
Merged

Add logfile_max_num feature #4548

merged 2 commits into from Sep 18, 2023

Conversation

tbeets
Copy link
Contributor

@tbeets tbeets commented Sep 15, 2023

Changes proposed in this pull request:

NATS Server 2.9 has logfile_size_limit option which allows the operator to set an optional byte limit on the NATS Server log file which when met causes a "rotation" such that the current log file is renamed (original file name appended with a time stamp to nanosecond accuracy) and a new log file is instantiated.

This PR is a new logfile_max_num companion option (alias log_max_num) which allows the operator to designate that the server should prune the total number of log files -- the currently active log file plus backups -- to the maximum setting.

A max value of 0 (the implicit default) or a negative number has meaning of unlimited log files (no maximum) as this is an opt-in feature.

A max value of 1 is effectively a truncate-only logging pattern as any backup made at rotation will subsequently be purged.

A max value of 2 will maintain the active log file plus the latest backup. And so on...

The currently active log file is never purged. Only backups are purged.

When enabled, backup log deletion is evaluated inline after each successful rotation event. To be considered for log deletion, backup log files MUST adhere to the file naming format used in log rotation as well as agree with the current logfile name and location. Any other files or sub-directories in the log directory will be ignored. E.g. if an operator makes a manual copy of the log file to logfile.bak that file will not be evaluated as a backup.

Typical use case:

This feature is useful in a constrained hosting environment for NATS Server, for example an embedded, edge-compute, or IoT device scenario, in which more featureful platform or operating system log management features do not exist or the complexity is not required.

@tbeets tbeets requested a review from a team as a code owner September 15, 2023 23:47
logger/log.go Outdated Show resolved Hide resolved
logger/log.go Outdated Show resolved Hide resolved
logger/log.go Outdated Show resolved Hide resolved
logger/log.go Outdated Show resolved Hide resolved
logger/log.go Show resolved Hide resolved
logger/log.go Show resolved Hide resolved
logger/log.go Outdated Show resolved Hide resolved
@tbeets tbeets changed the title Add logfile_max_archives feature Add logfile_max_num feature Sep 16, 2023
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@derekcollison derekcollison merged commit 22514a0 into main Sep 18, 2023
2 checks passed
@derekcollison derekcollison deleted the tgb/log-purge branch September 18, 2023 16:02
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.

None yet

2 participants