2

is there a possibility, to write with Boost Log the history log files in another folder than the current log file?

  • log
    • trace_2.log
    • history
      • trace_0.log
      • trace_1.log

I'm using an asynchronous sink and tried it via set_file_collector, but all logs are written to /tmp/log folder and when after closing the application, the file is moved to /tmp/log/history:

  sink->locked_backend()->set_file_name_pattern("/tmp/log/trace_%3N.log");
  sink->locked_backend()->set_file_collector(boost::log::sinks::file::make_collector(
        boost::log::keywords::target = "/tmp/log/history/"
    ));

When I try this without set_file_collector, the files are written to /tmp/log.

Thank you in advance!

  • I'm not sure what you're asking. As you said yourself, setting the file collector results in the older files moved to the `history` folder on rotation. – Andrey Semashev Aug 15 '22 at 11:41

1 Answers1

0

I found the solution. The configuration was not correct, so the settings enable_final_rotation = false does not worked on my side. Because of this, with each program exit, the current log file was moved to the history folder, also if it does not reached the rotation size. I forgot this information in the post.

This config was required:

boost::shared_ptr< boost::log::sinks::text_file_backend > backend =
    boost::make_shared< boost::log::sinks::text_file_backend >(
      boost::log::keywords::enable_final_rotation = false,
      boost::log::keywords::file_name = logPathAndFilename,
      ...
    );

sink->locked_backend()->set_file_collector(boost::log::sinks::file::make_collector(
        boost::log::keywords::target = logHistoryPath
    ));

sink->locked_backend()->scan_for_files();

core->add_sink(sink);
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 19 '22 at 02:23