Type: std::string
Class: fcf::NTest::Logger::Prefix
Package: fcfTest
File: test.hpp
Available from version: 1.2.1
A static string that is prepended to every log message matching the specified category.
The prefix property is a simple, static string that is automatically added to the beginning of log messages. It is ideal for adding constant visual markers, such as indentation or fixed labels, to specific categories of logs.
When a log message is processed, the logger checks if the message's category matches the prefix's category. If it does, the prefix string is inserted before the message content.
Example: Using a Static Prefix for Indentation
Demonstrating how to use the prefix property to add a constant indentation to all user-defined log messages.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE("PrefixDemo", "Logger", "StaticPrefixTest") {
// This log will be indented because of our custom prefix
fcf::NTest::log() << "Indented message" << std::endl;
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
fcf::NTest::Logger& logger = fcf::NTest::logger();
// 1. Create a new prefix object
fcf::NTest::Logger::Prefix prefix;
prefix.name = "indentation";
prefix.multiLine = true;
prefix.category = fcf::NTest::LMC_USER_GROUP;
// 2. Set the prefix to a static string
prefix.prefix = "[USER]: ";
// 3. Register the prefix
logger.appendPrefix(prefix);
// 4. Run the tests
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" -> "StaticPrefixTest" ...
> [USER]: Indented message
[SUCCESS] Test completed successfully (0.000`005`377 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`005`377 sec
By setting the prefix to " > ", every log message in the LMC_USER_GROUP category was automatically indented.