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

category from class fcf::NTest::Logger::MessageContext

Property: category

Type: unsigned int

Class: fcf::NTest::Logger::MessageContext

Package: fcfTest

File: test.hpp

Available from version: 1.1.14

The bitmask category of the log message.

The category property stores the message category as a bitmask. This allows the logger to filter messages or apply specific prefixes/formats based on the group (e.g., LMC_TEST_GROUP or LMC_USER_GROUP) or specific message IDs.

Example: Filtering by Category in Prefix

Demonstrating how to access the category property within a functional prefix to apply different formatting for different message groups.

#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