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

Rotating log files -- the wrong files are being deleted #145

Open
matthiasklein opened this issue Mar 20, 2021 · 1 comment
Open

Rotating log files -- the wrong files are being deleted #145

matthiasklein opened this issue Mar 20, 2021 · 1 comment

Comments

@matthiasklein
Copy link

When I run the following code https://paste.debian.net/1190133/ the second time, the wrong 00008.log file is deleted.

After run 1: (I copied the folder ...)

$ ls -ort logs-first-run/
-rw-r--r-- 1 mak 16363 20. Mär 11:33 file_00001.log
-rw-r--r-- 1 mak 16359 20. Mär 11:33 file_00002.log
-rw-r--r-- 1 mak 16359 20. Mär 11:33 file_00003.log
-rw-r--r-- 1 mak 16335 20. Mär 11:33 file_00004.log
-rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00005.log
-rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00006.log
-rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00007.log
-rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00008.log

After run 2:

$ ls -ort logs/
-rw-r--r-- 1 mak 16356 20. Mär 11:33 file_00007.log
-rw-r--r-- 1 mak 16344 20. Mär 11:34 file_00010.log
-rw-r--r-- 1 mak 16375 20. Mär 11:34 file_00011.log
-rw-r--r-- 1 mak 16359 20. Mär 11:34 file_00012.log
-rw-r--r-- 1 mak 16359 20. Mär 11:34 file_00013.log
-rw-r--r-- 1 mak 16335 20. Mär 11:34 file_00014.log
-rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00015.log
-rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00016.log
-rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00017.log
-rw-r--r-- 1 mak 16356 20. Mär 11:34 file_00018.log

I am using Boost 1.74.0 from Debian bullseye.

@Lastique
Copy link
Member

I believe, this is caused by a Boost.Filesystem limitation. The last write timestamps of a file provided by Boost.Filesystem only have granularity of one second, so often all rotated files have the same timestamp. In this situation, as no file is older than the other, Boost.Log removes files in the order they are returned by the filesystem, which is basically undefined.

Adding support for more fine grained timestamps in Boost.Filesystem has been in my TODO list for a while, but it won't be easy and it will be an API change. After this is done, the issue should resolve in Boost.Log.

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

No branches or pull requests

2 participants