flexi_logger/parameters/
cleanup.rs

1/// Defines the strategy for handling older log files.
2///
3/// Is used in [`Logger::rotate`](crate::Logger::rotate).
4///
5/// Note that if you use a strategy other than `Cleanup::Never`, then the cleanup work is
6/// by default done in an extra thread, to minimize the impact on the program.
7///
8/// See [`LoggerHandle::shutdown`](crate::LoggerHandle::shutdown)
9/// to avoid interrupting a currently active cleanup when your program terminates.
10///
11/// See
12/// [`Logger::cleanup_in_background_thread`](crate::Logger::cleanup_in_background_thread)
13/// if you want to control whether this extra thread is created and used.
14#[derive(Copy, Clone, Debug)]
15pub enum Cleanup {
16    /// Older log files are not touched - they remain for ever.
17    Never,
18
19    /// The specified number of rotated log files are kept.
20    /// Older files are deleted, if necessary.
21    KeepLogFiles(usize),
22
23    /// The specified number of rotated log files are compressed and kept.
24    /// Older files are deleted, if necessary.
25    #[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
26    #[cfg(feature = "compress")]
27    KeepCompressedFiles(usize),
28
29    /// Allows keeping some files as text files and some as compressed files.
30    ///
31    /// ## Example
32    ///
33    /// `KeepLogAndCompressedFiles(5,30)` ensures that the youngest five log files are
34    /// kept as text files, the next 30 are kept as compressed files with additional suffix `.gz`,
35    /// and older files are removed.
36    #[cfg_attr(docsrs, doc(cfg(feature = "compress")))]
37    #[cfg(feature = "compress")]
38    KeepLogAndCompressedFiles(usize, usize),
39}
40
41impl Cleanup {
42    // Returns true if some cleanup is to be done.
43    #[must_use]
44    pub(crate) fn do_cleanup(&self) -> bool {
45        !matches!(self, Self::Never)
46    }
47}