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

category from class fcf::NTest::Logger::Prefix

Property: category = fcf::NTest::LMC_ALL

Type: unsigned int

Class: fcf::NTest::Logger::Prefix

Package: fcfTest

File: test.hpp

Available from version: 1.1.13

Bitmask of message categories to which this prefix applies.

The category property acts as a filter for the prefix. It uses a bitmask system to determine which log messages should trigger the application of this specific prefix.

By using bitwise operations, you can assign a prefix to multiple categories at once or restrict it to a single specific group. For example, you can use LMC_TEST to apply a prefix to all test-related messages, or LMC_ALL to apply it to everything.

Example: Filtering prefixes by category

Demonstrating how to apply a prefix only to specific message categories using bitwise OR.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> int main(int a_argc, char* a_argv[]) { fcf::NTest::Logger& logger = fcf::NTest::logger(); logger.clearPrefixes(false); // 1. Create a prefix that ONLY applies to Test messages fcf::NTest::Logger::Prefix testOnlyPrefix; testOnlyPrefix.name = "test_only"; testOnlyPrefix.multiLine = false; testOnlyPrefix.category = fcf::NTest::LMC_USER_GROUP; testOnlyPrefix.prefix = "[USER] "; logger.appendPrefix(testOnlyPrefix); // 2. Create a prefix that applies to everything fcf::NTest::Logger::Prefix allPrefix; allPrefix.name = "all_prefix"; allPrefix.multiLine = false; allPrefix.category = fcf::NTest::LMC_ALL; allPrefix.prefix = "(LOG) "; logger.appendPrefix(allPrefix); // 3. Log a standard message (belongs to LMC_USER_GROUP by default) // This should only trigger 'all_prefix' logger.log() << "Standard user message" << std::endl; // 4. Log a test message // This should trigger BOTH 'test_only' and 'all_prefix' logger.log(fcf::NTest::LMC_TEST_GROUP) << "A test event occurred" << std::endl; return 0; }

Output:

[USER] (LOG) Standard user message (LOG) A test event occurred

The first log message only matched the fcf::NTest::LMC_ALL category. The second log message matched both the fcf::NTest::LMC_USER_GROUP and fcf::NTest::LMC_ALL categories, resulting in both prefixes being applied.