tracing icon indicating copy to clipboard operation
tracing copied to clipboard

max_log_files does not work on some systems due to metadata.created() failure

Open szy1231 opened this issue 1 year ago • 1 comments

Version

tracing-appender = "0.2.3"

Platform

CentOS Linux 7

Crates

tracing-appender

Description

In prune_old_logs, the function currently uses:

/// Err(Error { kind: Unsupported, message: "creation time is not available on this platform currently" })
let created = metadata.created().ok()?;

However, metadata.created() is not available on all platforms or filesystems. On my system (CentOS with [3.10.0-1160.119.1.el7.x86_64]), it always fails, which prevents max_log_files(2) from working as expected, leading to excessive log retention.

Expected behavior:

Old logs should be pruned correctly according to max_log_files(2), even if metadata.created() is unavailable.

Actual behavior:

Logs are not deleted because metadata.created() returns an error, causing prune_old_logs to fail early.

Suggested Fix

If metadata.created() fails, the function should fall back to metadata.modified(). If both are unavailable, extracting the timestamp from the filename (if applicable) could serve as an additional fallback. This would prevent log pruning from failing entirely due to missing creation timestamps.

Would you be open to a PR implementing this fallback logic? I can submit a PR if needed.

szy1231 avatar Feb 25 '25 11:02 szy1231

Should be fixed with #3000.

kaffarell avatar Feb 25 '25 14:02 kaffarell