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

system from class fcf::NTest::Logger::MessageContext

Property: system

Type: bool

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

Package: fcfTest

File: test.hpp

Available from version: 1.1.14

Flag indicating whether the log message should be treated as system message. System messages are not written to the logging stream.

All messages in the category code for which the fcf::NTest::LMC_SYSTEM_GROUP flag is set are considered system messages. This group is required to determine the testing status when generating custom output formats.

Example: Simulating System Output in a Custom Formatter

Demonstrating how a custom formatter can use the system flag to change the visual style of messages marked as system-level.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> #include <string> void initialize(){ fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Setup a custom format fcf::NTest::Logger::Format format; format.name = "sys-format"; // A custom formatter that adds a special prefix to system messages format.handler = []( fcf::NTest::Logger&, fcf::NTest::Logger::MessageContext& a_context) { if (a_context.system) { // If it is a system message, wrap it in brackets std::stringstream prefix; prefix << "[SYSTEM 0x"<< std::hex << a_context.category << "] "; a_context.message = prefix.str() + a_context.message; // Reset the system message flag so that the data is output to the stream a_context.system = false; } }; logger.appendFormat(format); } FCF_TEST_DEFINE("SystemDemo", "Logger", "SystemOutputTest") { // 2. Log a standard user message // This will NOT have the [SYSTEM] prefix because system is false by default fcf::NTest::log() << "Standard user message" << std::endl; // 3. Simulate a system message // Since we cannot easily trigger system via standard API without internal access, // we demonstrate the logic that the Logger uses when a category is LMC_SYSTEM_GROUP. // In the implementation, messages with LMC_SYSTEM_GROUP automatically set system flag to true. fcf::NTest::log(fcf::NTest::LMC_SYSTEM_GROUP) << "My system event!" << std::endl; } int main(int a_argc, char* a_argv[]) { initialize(); bool error = false; // Run the tests fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

[SYSTEM 0x80010001] [SYSTEM 0x80020001] Performing the test: "SystemDemo" -> "Logger" -> "SystemOutputTest" ... > Standard user message [SYSTEM 0x80000000] My system event! [SUCCESS] Test completed successfully (0.000`009`496 sec) [SYSTEM 0x80020003] [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`009`496 sec [SYSTEM 0x80010002]

The application must be run by specifying the format via a command-line parameter:

app --test-format "sys-format"