fcf::NTest::ELogMessageCategory enum
Type: fcf::NTest::ELogMessageCategory
Package: fcfTest
File: test.hpp
Available from version: 1.1.14
Defines bitmask-based categories for log messages, allowing for granular filtering and specialized formatting of diagnostic output.
Enum items
LMC_ROOT_GROUP
=
0x00010000
- The base category for all root-level system messages, including test execution lifecycle, summary, and runner errors.
LMC_SYSTEM_GROUP
=
2147483648
- A category bit mask representing internal system messages. Messages in this group are typically treated as internal software events and are not output to the logging output stream.
LMC_LAUNCH_GROUP
=
0x00020000
- The category for messages related to the lifecycle of an individual test case, such as its start, descriptive messages, and completion.
LMC_TEST_GROUP
=
0x00040000
- The category for messages directly related to test results, including success notifications, failure reports, and detailed error descriptions.
LMC_USER_GROUP
=
0x00080000
- The category for user-defined diagnostic messages, allowing developers to inject custom logs into the framework's logging system.
LMC_ROOT_START
=
0x80010001
- Indicates the start of the entire test execution process.
LMC_ROOT_END
=
0x80010002
- Indicates the end of the entire test execution process.
LMC_ROOT_COMPLETE
=
0x00010003
- Indicates the overall completion status of the test execution process.
LMC_ROOT_ERROR
=
0x00010004
- Indicates general error messages encountered during the test runner execution process.
LMC_ROOT_SUMMARY
=
0x00010005
- Indicates the presentation of the final test results summary, including counts of passed, failed, and skipped tests.
LMC_ROOT_DURATION
=
0x00010006
- Indicates the reporting of the total execution time for the entire test suite.
LMC_ROOT_RUN_ERROR
=
0x00010007
- Indicates errors that occur specifically during the execution phase of the test runner.
LMC_ROOT_NEW_LINE
=
0x00010008
- A special marker used to insert a new line in the log output, typically for visual separation.
LMC_LAUNCH_START
=
0x80020001
- Indicates the start of an individual test case execution.
LMC_LAUNCH_END
=
0x80020003
- Indicates the end of an individual test case execution.
LMC_TEST_ERROR
=
0x00040002
- Indicates that a test case has failed due to an assertion error.
LMC_TEST_ERROR_MESSAGE
=
0x00040003
- Provides the detailed error description and diagnostic data for a failed test.
LMC_ALL
=
0xFFFF0000
- A bitmask that selects all available message categories.
The fcf::NTest::ELogMessageCategory enumeration is used to categorize every log message produced by the framework. It is designed as a bitmask, which allows a single log message to belong to multiple categories simultaneously, or for a logger to filter messages based on a combination of categories.
| 4 bytes |
| two high bytes |
two low bytes |
|
The high two bytes are the message category/type.
When determining whether a message matches a given type, a check is performed using the & operator.
|
The low two bytes are the message number.
And the equality check is performed if it is not zero.
If the low-order bytes are zero, then all common bytes from the specified group are selected.
|
Example check for prefix output:
const unsigned int hmask = 0xffff0000 & prefix.options.messageCategory;
const unsigned int lmask = 0x0000ffff & prefix.options.messageCategory;
if ( messageCategory & hmask && (lmask == 0 || lmask == (0x0000ffff & messageCategory)) ) {
...
}
Each member of the fcf::NTest::ELogMessageCategory class represents a specific semantic grouping of a log entry. This categorization is necessary for fcf::NTest::Logger's advanced filtering capabilities and to ensure that specialized formatters (such as the JUnit formatter) can correctly interpret the message context.
Example: Filtering Logs by Category
Demonstrates how to use specific categories when logging and how to apply prefixes that only target certain categories.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
enum {
MY_LOG_COMMAND = fcf::NTest::LMC_USER_GROUP | 0x0001,
};
FCF_TEST_DECLARE("CategoryDemo", "Logging", "FilterTest") {
// 1. Access the global logger
fcf::NTest::Logger& logger = fcf::NTest::logger();
// 2. Clear existing settings for a clean demonstration
logger.clearPrefixes(false);
// 3. Add a prefix that ONLY applies to User-defined messages (LMC_USER)
fcf::NTest::Logger::Prefix prefix;
prefix.name = "my-command";
prefix.multiLine = false;
prefix.category = MY_LOG_COMMAND;
prefix.prefix = "[MY COMMAND] ";
logger.appendPrefix(prefix);
// 4. Log messages using different categories
// This will have both prefixes: | [MY COMMAND]
fcf::NTest::log(MY_LOG_COMMAND) << "This is a my command message." << std::endl;
fcf::NTest::log() << "This is a simple user message." << std::endl;
// 5. Set the logger to its default 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" -> "Logging" -> "FilterTest" ...
[MY COMMAND] This is a my command message.
This is a simple user message.
[SUCCESS] Test completed successfully (0.000`006`029 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`006`029 sec