category from class fcf::NTest::Logger::MessageContext
Property: category
Type:
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.1.14
The bitmask category of the log message.
The
Example: Filtering by Category in Prefix
Demonstrating how to access the
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DEFINE ("CategoryDemo", "Logger", "CategoryTest") {
fcf::NTest::Logger & logger = fcf::NTest::logger ();
// 1. Register a functional prefix that checks the category
fcf::NTest::Logger::Prefix prefix;
prefix.name = "category-prefix";
prefix.multiLine = false;
prefix.category = fcf::NTest::LMC_ALL ;
prefix.handler = []( fcf::NTest::Logger & a_logger, fcf::NTest::Logger::MessageContext & a_context) {
// Check if the message belongs to the USER group
if (a_context.category & fcf::NTest::LMC_USER_GROUP ) {
return "[USER] ";
}
// Otherwise, if it's a TEST group message
if (a_context.category & fcf::NTest::LMC_TEST_GROUP ) {
return "[TEST] ";
}
return "[OTHER] ";
};
logger.appendPrefix (prefix);
// 2. Log messages from different categories
fcf::NTest::log () << "This is a user message." << std::endl;
fcf::NTest::log (fcf::NTest::LMC_TEST_GROUP ) << "This is a test info message." << std::endl;
// 3. Restoring the logger's state
logger.clearPrefixes (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: "CategoryDemo" -> "Logger" -> "CategoryTest" ...
> [USER] This is a user message.
[TEST] This is a test info message.
[SUCCESS] Test completed successfully (0.000`011`442 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`011`442 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.