-
Notifications
You must be signed in to change notification settings - Fork 105
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
The file name rule for daily rotate log? #49
Comments
Yes, mostly. The file counter is incremented whenever a new file name is generated by the sink backend. This happens whenever the log file is rotated. In certain cases though the counter is not incremented - mostly when the backend is supposed to append to an existing file. For example, as a recovery measure against the filesystem was being full and now having free space. In this case the file stream would be marked as bad (because the previous write failed) and the sink reopens the same file to attempt to continue writing to it. The counter can be updated to a starting value by calling
This requires the sink backend to be coupled with the file name generator. In particular, the sink would have to know that the generated filename without the counter has changed (i.e. from 2018-01-11 to 2018-01-12 or from 2018-01-11_23_59_59 to 2018-01-12_00_00_00 or whatever the generator produces). I don't like that kind of coupling. I suppose, I could extend the interface of the backend to allow users to set their own file name generators instead of relying just on the filename pattern. That would allow you to implement any behavior you want without the added coupling. But on the other hand, it would break |
I haven't go through the code, it is too complex for me. In my experience, a 'counter' generating strategy could be introduced:
The global strategy could be used as default. Generally speaking the filename generating and counter management could be handled in filename generator with counter strategy (as well as other strategies). However, in practice, the intention of 'counter' is for distinguish filenames; but if the major part of filename has already been significantly changed, the counter part is not very helpful therefore should be reset. So the introducing a strategy idea is might be over-engineering. I guess most users want to use logging library out-of-the-box with a few configurations. It could handle most of common cases, only need to be extended for some particular cases (for example a different persistence layer). |
App_2018-01-09.7.log I think have some problem with log file number auto increment with no limit. |
I was wondering if there any plans to resolve this in some way. My team is presently working on the control software for the new telescope for Cherekov Telescope Array, we're trying to use Boost (already our dependency) for logging. However we are required to use the "filename based" as opposed to "global" (using the terms from the post above) counter in the logs, so we've also faced this issue. |
No specific plans. The counter and timestamp are designed to work independently at present and there is no easy way to change it. There is no analysis of a would-be filename without the counter and frankly I don't fully understand how that would work. If the current counter behavior does not suit you, my suggestion is to just not use it and instead use a more precise timestamp in the filename. |
I imagine a way to realize this would be to have an additional, joint date/counter name generator, triggered by the presence of the specific formatter (say "%n" instead of "%N") in the log name specification. The generator may keep the presently used date and reset the counter when the date changes. Unable to say how difficult would it be to implement this given the present name generation logic, I rely here on your good judgement. Regarding alternating the log name format, I'm afraid this is not in my team's hands (event if personally I'd be also in favor of finer time stamps). Nevertheless, thank you for considering this. Will look for another option then. |
You can always write a custom sink backend that implements the behavior you require. Although that will involve more than just filename generation. |
I posted a thread on stackoverflow few months ago, no one answered it. It's not very urgent since it is only log file name so I just left it.
Recently I noticed that the changelog of 1.66.0 said it has been fixed.
For me I still have some issues about the file name. I can see some log file names after I upgrade boost to 1.66.0 just like it behaves in 1.65.1.
Here's the code:
Here's some log file examples:
My understanding is that the counter and date-time part are unrelated, the counter increases whenever a new file is being created. Is my understanding correct?
But this makes the file names confusing. For example:
Is this the current behavior?
If so, my suggestion is to reset the file counter for a new day like this:
Does this make sense?
The text was updated successfully, but these errors were encountered: