void
appendPrefix(
const fcf::NTest::Logger::Prefix& a_prefix,
bool a_appendToFront
= false)
Class: fcf::NTest::Logger
Package: fcfTest
File:
test.hpp
(
link_to_the_declaration_in_the_file
,
link_to_the_implementation_in_the_file
)
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.
bool a_appendToFront = false
-
[SINCE 1.2.9]
If set to false, the new prefix is added to the end of the prefix queue (default behavior).
If set to true, the new prefix is added to the beginning of the prefix queue.
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_DEFINE("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.