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

Adds a check in tracing_appender #2826

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tracing-appender/src/rolling/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ impl Builder {
/// Files matching these criteria may be deleted if the maximum number of
/// log files in the directory has been reached.
///
/// # Panics
///
/// This method panics if and only if `n` is 0.
///
/// [`filename_prefix`]: Self::filename_prefix
/// [`filename_suffix`]: Self::filename_suffix
///
Expand All @@ -227,6 +231,7 @@ impl Builder {
/// ```
#[must_use]
pub fn max_log_files(self, n: usize) -> Self {
assert!(n != 0, "must keep at least one log file");
Self {
max_files: Some(n),
..self
Expand Down Expand Up @@ -271,3 +276,15 @@ impl Default for Builder {
Self::new()
}
}

#[cfg(test)]
mod tests {
use super::Builder;

/// Test that [`Builder::max_log_files`] panics if `n` is 0.
#[test]
#[should_panic(expected = "must keep at least one log file")]
fn test_zero_max_log_files() {
let _ = Builder::new().max_log_files(0);
}
}
Loading