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

Append & rotate on short running program... #122

Closed
gskapka opened this issue Oct 5, 2022 · 3 comments
Closed

Append & rotate on short running program... #122

gskapka opened this issue Oct 5, 2022 · 3 comments

Comments

@gskapka
Copy link

gskapka commented Oct 5, 2022

I have the logger setup:

Logger::try_with_str("info")
    .and_then(|logger| {
        logger
            .log_to_file(FileSpec::default().directory("./logs"))
            .rotate(
                Criterion::Age(Age::Second),
                Naming::Timestamps,
                Cleanup::KeepLogAndCompressedFiles(2, 2),
            )
            .append()
            .start()
    })
    .and_then(|_| ...)

...in a binary which is not long running, and instead is called multiple times via CLI commands.

The .append works fine, a log file is created in the expected dir, and all program logs are appended therein.

However the rotation doesn't appear to take effect whatsoever.

What am I doing wrong?

@emabee
Copy link
Owner

emabee commented Oct 6, 2022

You're doing fine :-)

The issue is real, and described in the docs, at Criterion::Age.
On unix (and Mac), the filesystems maintains only a LAST_MODIFIED_AT, not a CREATED_AT property of files. On Windows, there is a CREATED_AT property, but Windows does a weird trick to make it unusable for our case. So flexi_logger "invents" the value for CREATED_AT for the first file (it uses the current timestamp).

With many short program runs, using Criterion::Size for rotation might be a better way out, or disabling append.

@gskapka
Copy link
Author

gskapka commented Oct 6, 2022

Ah damn! Very sorry to have troubled you in that case - I should have spotted that in the docs.

As it happens I was just playing further and had discovered that it works perfectly as expected if I use size as a criterion - exactly like you said, so I'll switch to that method.

Thank you for the prompt reply though, and for the excellent crate.

Closing as solved.

@emabee
Copy link
Owner

emabee commented Oct 6, 2022

I added an improvement to the logic you were using, which should help significantly for your case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants