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

scan_for_files skips file count #125

Closed
ghost opened this issue Aug 20, 2020 · 1 comment
Closed

scan_for_files skips file count #125

ghost opened this issue Aug 20, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 20, 2020

I set up a text_file_backend to rotate log files with a counter appended to the target file name

auto backend = boost::make_shared<sinks::text_file_backend>(
  keywords::file_name = "foo.log",
  keywords::target_file_name = "foo.log.%N",
  keywords::rotation_size = 10,	// small size for testing
  keywords::open_mode = std::ios_base::out | std::ios_base::app
);
using file_sink = sinks::asynchronous_sink<sinks::text_file_backend>;
auto sink = boost::make_shared<file_sink>(backend);

sink->locked_backend()->set_file_collector(
  boost::log::sinks::file::make_collector(
    keywords::target = log_dir,
    keywords::max_files = 10
  )
);

sink->locked_backend()->scan_for_files();
logging::core::get()->add_sink(sink);

If I set up a program to log 3 entries during one run of the program. After two runs, the logs look like:

$ ls foo.log*
foo.log  foo.log.1  foo.log.2  foo.log.4  foo.log.5

The rotation works except foo.log.3 was skipped. If instead I log 2 entries (the second one to cause a file rotation) during one run of the program, and run it 6 times I get:

$ ls foo.log*
foo.log    foo.log.11  foo.log.5  foo.log.9
foo.log.1  foo.log.3   foo.log.7

We get only odd numbers because one count was skipped at each start of the program (at scan_for_files)

I tried making the rotation_size bigger, putting the counter elsewhere (e.g. in the middle of the file name), not opening the file in append mode, but to no avail.

I am using Boost 1.73

@Lastique
Copy link
Member

Thanks for the report, should be fixed now in develop.

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

1 participant