Class: fcf::NTest::Logger
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
Clears the current prefixes from the logger, optionally restoring default ones.
The clearPrefixes method is used to remove all currently configured fcf::NTest::Logger::Prefix objects from the logger.
The method provides two modes of operation via the a_defaultState parameter:
- Full Clear: If a_defaultState is false (default), all prefixes are removed, leaving the logger with no prefixes.
- Reset to Defaults: If a_defaultState is true, all existing prefixes are cleared, and a set of standard default prefixes is automatically re-added.
Arguments
bool a_defaultState = false
- If true, the logger will restore its default prefix configuration after clearing the current ones. If false, the logger will have no prefixes.
Example: Clearing and Resetting Prefixes
Demonstrating how to completely remove all prefixes and how to restore the default logger state using a_defaultState.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DECLARE("PrefixDemo", "Logger", "ClearPrefixesTest") {
fcf::NTest::Logger& logger = fcf::NTest::logger();
// 1. Add a custom prefix
fcf::NTest::Logger::Prefix customPrefix;
customPrefix.name = "custom";
customPrefix.prefix = "[CUSTOM] ";
customPrefix.category = fcf::NTest::LMC_ALL;
logger.appendPrefix(customPrefix);
// 2. Verify the prefix is active
fcf::NTest::log() << "Testing custom prefix" << std::endl;
// 3. Completely clear all prefixes
logger.clearPrefixes(false);
fcf::NTest::log() << "Testing after full clear" << std::endl;
// 4. Reset to default prefixes
logger.clearPrefixes(true);
fcf::NTest::log() << "Testing after reset to defaults" << 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: "PrefixDemo" -> "Logger" -> "ClearPrefixesTest" ...
> [CUSTOM] Testing custom prefix
Testing after full clear
> Testing after reset to defaults
[SUCCESS] Test completed successfully (0.000`010`406 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`010`406 sec
The clearPrefixes method allows for easy management of the logger's visual style, providing both a 'blank slate' option and a 'factory reset' option.