From 2d9f4801986faa1762b2ce82ecf8d5275bc72e18 Mon Sep 17 00:00:00 2001 From: "chuanzhi.dcz" Date: Tue, 27 May 2025 14:47:18 +0800 Subject: [PATCH] Use file's mtime instead of created time to sort. First, rolling based on modified time and created time should not be much different. On the other hand, because the created time attribute has higher requirements for the Linux kernel version (>=4.11), while the modified time does not have this restriction, it has a wider range of usage scenarios. When the host Linux kernel version is less than 4.11, the roll function is not available, which will lead to more and more log files, and then cause the disk to be full. --- tracing-appender/src/rolling.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tracing-appender/src/rolling.rs b/tracing-appender/src/rolling.rs index ef931b37e0..b1357b0cb3 100644 --- a/tracing-appender/src/rolling.rs +++ b/tracing-appender/src/rolling.rs @@ -602,8 +602,8 @@ impl Inner { return None; } - let created = metadata.created().ok()?; - Some((entry, created)) + let modified = metadata.modified().ok()?; + Some((entry, modified)) }) .collect::>() }); @@ -619,8 +619,8 @@ impl Inner { return; } - // sort the files by their creation timestamps. - files.sort_by_key(|(_, created_at)| *created_at); + // sort the files by their modification timestamps. + files.sort_by_key(|(_, modified_at)| *modified_at); // delete files, so that (n-1) files remain, because we will create another log file for (file, _) in files.iter().take(files.len() - (max_files - 1)) {