-
Notifications
You must be signed in to change notification settings - Fork 56
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
Rotation may overwrite existing log file #150
Comments
I think you ran through the following within one sec: Rcurrent.log This wasn‘t possible without the explicitly triggered rotation. Fix should not be difficult. |
I am not sure I follow. So during the first rotate It does not look like the issue gets triggered for further rotation as long as the app does not get restarted. I think I will try the |
Ts1 is meant to be in all cases the timestamp of the infix in the filename. It has precision of second, that‘s why the collision can happen if all actions are done in a single second. Collisions during rotate are detected and escaped with adding restartXXX to the infix. |
Yes, lack of collision detection during compression is an issue, you probably should use something like Let's say I have After 5 minutes during which a bunch of logs were written into the current file I execute rotation command again. I would expect to get 3 files: The third manual rotation at 18:40 which contains logs from 18:35 to 18:40 gets rotated with name So it looks like the code chooses timestamp for rotated files incorrectly. The first rotation after cold start uses "current" file creation timestamp, while the subsequent ones use incorrectly cached values. The issue may not be even specific to manual rotation, it's just the easiest way to trigger it. |
I think the issue is caused by this line. You use creation date of rotated file for naming next rotated file. It's wrong by itself as can be seen in my previous comment (you should use current time instead), but it causes name collision when appending is enabled. During initialization you use creation date of current file, which inevitable becomes creation date of next rotation file since you use |
- with sub-second rotations - with cleanup when all logfiles should be compressed
Issues are now hopefully all fixed with 0.27.1. Thanks for reporting and the discussions! |
As per my two previous comments, I don't think this issue is fully fixed. Yes, v0.27.1 no longer overwrites previously rotated log files on compression, but it still uses arguably incorrect timestamps for naming rotated files. After rotating twice today with existing current file created two days ago I got the following files:
The second file contains records only from 2023-09-27 16:17:42 to 2023-09-27 16:17:48. |
Sorry for not replying to this part directly. I was distracted by testing and resolving the naming conflicts that also existed. |
Thank you! I confirm that 0.27.2 has fixed the issue. |
I have an app which allow to remotely manage logs. It uses
Cleanup::KeepCompressedFiles
, i.e. it compresses logs immediately after rotation. It has commands to list, rotate, and copy (rotated) logs.After cold start of the application with existing logs, the list command produces the following output:
Next, the rotate command is executed with the following result (it returns only rotated and compresses logs):
Listing logs result in expected result:
So far so good. But if I manually rotate again (more than one second later), the last 2 KB log file gets replaced with new data:
Parts of relevant code:
Rotating logs after that without restarting the application works without issues.
I can not provide a minimal reproduction of the issue right now. Hopefully, you will be able to resolve the issue with provided information.
The text was updated successfully, but these errors were encountered: