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

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

void appendPrefix(const fcf::NTest::Logger::Prefix& a_prefix)

Class: fcf::NTest::Logger

Package: fcfTest

File: test.hpp

Available from version: 1.2.1

Adds a new prefix configuration to the logger.

The appendPrefix method allows you to add a new fcf::NTest::Logger::Prefix to the logger's current collection of prefixes.

If a prefix with the same name already exists in the logger, the existing configuration will be updated with the new settings. If no prefix with the matching name is found, a new prefix entry is created and added to the list.

Arguments

const fcf::NTest::Logger::Prefix& a_prefix
- The prefix configuration to be added or updated in the logger.

Example: Adding and Updating a Prefix

Demonstrating how to add a new prefix and then update its configuration using the same name.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DECLARE("PrefixDemo", "Logger", "AppendPrefixTest") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Create a new prefix fcf::NTest::Logger::Prefix prefix; prefix.name = "my-prefix"; prefix.prefix = "[NEW] "; prefix.category = fcf::NTest::LMC_USER_GROUP; prefix.multiLine = false; // 2. Add the prefix to the logger logger.appendPrefix(prefix); // 3. Verify by logging a message fcf::NTest::log() << "First message with new prefix" << std::endl; // 4. Update the existing prefix by using the same name prefix.prefix = "[UPDATED] "; logger.appendPrefix(prefix); // 5. Verify the update fcf::NTest::log() << "Second message with updated 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" -> "AppendPrefixTest" ... > [NEW] First message with new prefix > [UPDATED] Second message with updated prefix [SUCCESS] Test completed successfully (0.000`008`938 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`008`938 sec

The appendPrefix method ensures that prefixes are managed by their unique name, allowing for easy updates without needing to clear the entire collection.