FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

clearFormats() method from fcf::NTest::Logger class

void clearFormats(bool a_defaultState = false)

Class: fcf::NTest::Logger

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Clears all current formatting configurations from the logger.

The clearFormats method removes all registered fcf::NTest::Logger::Format objects from the logger.

This method is useful when you want to reset the logger's output behavior or when you are performing a complete reconfiguration of the logging targets and their associated formats.

Arguments

bool a_defaultState = false
- If true (default behavior for reset), the logger will automatically re-add the default format (usually "junit") after clearing the existing ones. If false, the logger will be left with no formats configured.

Example: Clearing Formats with Default Reset

Demonstrating how to clear all custom formats and restore the default formatting configuration using the a_defaultState parameter.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("FormatDemo", "Logger", "ClearFormatsTest") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Add a custom format to the logger fcf::NTest::Logger::Format customFormat; customFormat.name = "my-custom-format"; // (In a real scenario, a handler would be assigned here) logger.appendFormat(customFormat); // 2. Verify the custom format is present fcf::NTest::log() << "Formats before clearing: " << logger.formats().size() << std::endl; // 3. Clear all formats and restore the default one logger.clearFormats(true); // 4. Verify that the default format is back fcf::NTest::log() << "Formats after reset: " << logger.formats().size() << std::endl; for(const auto& format : logger.formats()) { fcf::NTest::log() << " - Active format: " << format.name << std::endl; } FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

Performing the test: "FormatDemo" -> "Logger" -> "ClearFormatsTest" ... > Formats before clearing: 2 > Formats after reset: 1 > - Active format: junit [SUCCESS] Test completed successfully (0.000`019`798 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`019`798 sec

By passing true to clearFormats, the logger ensures that at least one valid formatting rule (the default one) remains active.