c++boostboost-log

Boost Log + Log rotation in another folder


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

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!


Solution

  • 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);