These flags are used: "keywords::open_mode = std::ios_base::app" and "keywords::rotation_size = <some_value>"
After running application few times, I get two log files: sample_0.log and sample_1.log
When I run application again I get strange behaviour (and problem):
Observed behaviour: the 1st log message goes to the 1st log-file (sample_0.log) and the rest goes to the 2nd log-file.
Expected behaviour: All the log-messages should go to the 2nd log-file (sample_1.log)
Here is the code:
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/file.hpp>
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
void init_logging()
{
logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity");
logging::add_file_log(
keywords::file_name = "sample_%N.log",
keywords::open_mode = std::ios_base::app,
keywords::auto_flush = true,
keywords::rotation_size = 1 * 1024,
keywords::max_size = 3 * 1024,
keywords::format = "%LineID%. [%TimeStamp%][%ThreadID%] [%Severity%] - %Message%");
logging::core::get()->set_filter(logging::trivial::severity >= logging::trivial::info);
logging::add_common_attributes();
}
int main(int, char*[])
{
init_logging();
BOOST_LOG_TRIVIAL(trace) << "This is a trace severity message";
BOOST_LOG_TRIVIAL(debug) << "This is a debug severity message";
BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";
BOOST_LOG_TRIVIAL(warning) << "This is a warning severity message";
BOOST_LOG_TRIVIAL(error) << "This is an error severity message";
BOOST_LOG_TRIVIAL(fatal) << "This is a fatal severity message";
return 0;
}
Where am I wrong? (I use gcc 9.3.0 and Boost 1.71)