Skip to content

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

Open
@szy1231

Description

@szy1231

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions