Fooble
Fooble

Reputation: 485

Boost.Log 'max_files' configuration not being applied

EDIT: The version of Boost being used is 1.71.0

I'm having a bit of trouble getting my Boost.Log configuration work as I want.

Here is the code being used to configure Boost.Log:

    std::filesystem::path logFileFolder = std::filesystem::current_path();
    logFileFolder.append("Logs");

    auto workingFile = logFileFolder;
    workingFile.append("Temp.log");

    auto finalFile = logFileFolder;
    finalFile.append("Log.%2N.log");

    constexpr auto fileSize = 10 * 1024;

    boost::log::add_file_log(
        boost::log::keywords::file_name = workingFile,
        boost::log::keywords::target_file_name = finalFile,
        boost::log::keywords::rotation_size = fileSize,
        boost::log::keywords::max_size = fileSize,
        boost::log::keywords::format = LogFormatterFunctionJSON,
        boost::log::keywords::auto_flush = true,
        boost::log::keywords::enable_final_rotation = true,
        boost::log::keywords::max_files = 10
    );

However on running the application more than 10 log files are being created:

Too many log files!

I have tried many other option combinations and have had no luck. Is there some glaringly obvious mistake I have made when configuring my log file?

Upvotes: 2

Views: 749

Answers (1)

Fooble
Fooble

Reputation: 485

So it looks like the issue was that I was missing the "target" keyword in the add_file_log call.

std::filesystem::path logFileFolder = std::filesystem::current_path();
logFileFolder.append("Logs");

auto workingFile = logFileFolder;
workingFile.append("Temp.log");

auto finalFile = logFileFolder;
finalFile.append("Log.%2N.log");

constexpr auto fileSize = 10 * 1024;

boost::log::add_file_log(
    boost::log::keywords::file_name = workingFile,
    boost::log::keywords::target_file_name = finalFile,
    boost::log::keywords::rotation_size = fileSize,
    boost::log::keywords::max_size = fileSize,
    boost::log::keywords::format = LogFormatterFunctionJSON,
    boost::log::keywords::auto_flush = true,
    boost::log::keywords::enable_final_rotation = true,
    boost::log::keywords::max_files = 10,
    boost::log::keywords::target = logFileFolder // <=== This was required
);

Upvotes: 2

Related Questions