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

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

fcf::NTest::Logger::Prefixes prefixes()
void prefixes(fcf::NTest::Logger::Prefixes a_prefixes)

Class: fcf::NTest::Logger

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Provides access to the current collection of prefix configurations.

The prefixes method provides access to the current set of fcf::NTest::Logger::Prefix objects configured in the logger.

This method has two distinct behaviors depending on whether it is used for reading or writing:

  • Read Mode: When called without arguments, it returns a copy of the current list of prefixes (fcf::NTest::Logger::Prefixes). This is useful for inspecting the current logger configuration.
  • Write Mode: When called with a fcf::NTest::Logger::Prefixes object as an argument, it replaces the existing collection of prefixes with the provided one.

Arguments

fcf::NTest::Logger::Prefixes a_prefixes
- The new collection of prefixes to be set in the logger.
Result
fcf::NTest::Logger::Prefixes
- A copy of the current list of prefixes.

Example: Reading and Replacing Prefixes

Demonstrating how to retrieve the current prefixes and then replace them with a new custom configuration.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("PrefixDemo", "Logger", "PrefixesAccess") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Retrieve the current prefixes (Read Mode) fcf::NTest::Logger::Prefixes currentPrefixes = logger.prefixes(); std::cout << "Current number of prefixes: " << currentPrefixes.size() << std::endl; // 2. Create a new set of prefixes fcf::NTest::Logger::Prefix newPrefix; newPrefix.name = "custom-prefix"; newPrefix.prefix = "[CUSTOM] "; newPrefix.category = fcf::NTest::LMC_ALL; newPrefix.multiLine = false; fcf::NTest::Logger::Prefixes newPrefixes(currentPrefixes); newPrefixes.push_back(newPrefix); // 3. Replace the existing prefixes (Write Mode) logger.prefixes(newPrefixes); // 4. Verify the change by logging a message fcf::NTest::log() << "This message should have the custom prefix." << 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" -> "PrefixesAccess" ... Current number of prefixes: 2 > [CUSTOM] This message should have the custom prefix. [CUSTOM] [SUCCESS] Test completed successfully (0.000`020`602 sec) [CUSTOM] [CUSTOM] [SUCCESS] All tests were completed. [CUSTOM] Tests: 1 passed, 0 failed, 0 skipped, 1 total [CUSTOM] Duration: 0.000`020`602 sec

The prefixes method effectively allows both inspection and complete reconfiguration of the logger's prefixing behavior.