Comments (7)
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?
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 scan_for_files
on the backend. The call will attempt to discover the last used counter value and start counting new files from the next value. The fix in 1.66 was related to this call. This method may not be exactly what you want, but it may be better than always starting from 0.
If so, my suggestion is to reset the file counter for a new day like this:
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 scan_for_files
, because it needs the filename pattern. I'm not sure what the solution is here.
from log.
I haven't go through the code, it is too complex for me. In my experience, a 'counter' generating strategy could be introduced:
- global - increases no matter the filename with/without the counter has changed
- filename based - only increases when for same filename without counter or reset for new filename
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).
from log.
App_2018-01-09.7.log
App_2018-01-10.8.log
App_2018-01-10.0.log
App_2018-01-11.1.log
App_2018-01-11.0.log
I think have some problem with log file number auto increment with no limit.
Example App_2018-01-11.999999999999999999999.log
from log.
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.
from log.
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.
from log.
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.
from log.
You can always write a custom sink backend that implements the behavior you require. Although that will involve more than just filename generation.
from log.
Related Issues (20)
- Redirect log records to specific sink only HOT 4
- Max file rotating under the same target directory HOT 1
- BOOST_LOG_TRIVIAL cannot find overloaded `operator<<()` when it's declared in global scope HOT 2
- using BOOST_LOG_TRIVIAL << with string greater than max_size_decor results in bufferoverlfow detected HOT 3
- An infinite loop occurs when boost writes to the log file HOT 4
- Timezone information with text file backend HOT 2
- Boost.Log rotation may throw boost::filesystem::filesystem_error HOT 10
- How to add timezone info for log entries and log filename HOT 3
- Formatting TimeStamp HOT 1
- Boost 1.82, boost\Log\trivial unresolved external symbol error if included after curl HOT 3
- Log Formatting [Conan 2.x, C++20, Boost 1.83] HOT 2
- 1.82.0 compiled for XP uses AcquireSRWLockExclusive HOT 2
- How to append log to same log file after program restarts? HOT 1
- CMake integration for Xcode universal 2 builds HOT 1
- boost日志在动态库里被使用,再次在主程序中使用会崩溃 HOT 1
- Boost stopped printing logs after changing the system time HOT 4
- Redundent call to boost_install() HOT 1
- An infinite loop occurs when boost writes to the log file (Debug Mode, Medium size file) HOT 1
- Consider switching dependency from MPL to MP11 HOT 2
- Please consider improving the documentation and examples HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.