Coder Social home page Coder Social logo

Comments (7)

Lastique avatar Lastique commented on July 16, 2024

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.

sinall avatar sinall commented on July 16, 2024

I haven't go through the code, it is too complex for me. In my experience, a 'counter' generating strategy could be introduced:

  1. global - increases no matter the filename with/without the counter has changed
  2. 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.

hoangtocdo90 avatar hoangtocdo90 commented on July 16, 2024

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.

IevgenVovk avatar IevgenVovk commented on July 16, 2024

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.

Lastique avatar Lastique commented on July 16, 2024

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.

IevgenVovk avatar IevgenVovk commented on July 16, 2024

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.

Lastique avatar Lastique commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.