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

level from class fcf::NTest::Logger::MessageContext

Property: level

Type: fcf::NTest::ELogLevel

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

Package: fcfTest

File: test.hpp

Available from version: 1.1.14

The severity level of the log message.

The level property indicates the severity of the current log entry. This allows prefixes and formatters to change their behavior based on the importance of the message (e.g., coloring an error message red or adding a "[ERROR]" prefix).

Example: Severity-based Prefixing

Demonstrating how to use the level property to add specific visual indicators based on the log severity.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("LevelDemo", "Logger", "SeverityTest") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Register a functional prefix that reacts to the log level fcf::NTest::Logger::Prefix prefix; prefix.name = "severity-prefix"; prefix.multiLine = false; prefix.category = fcf::NTest::LMC_ALL; prefix.handler = []( fcf::NTest::Logger& a_logger, fcf::NTest::Logger::MessageContext& a_context) { switch (a_context.level) { case fcf::NTest::LL_ERR: return "!!! ERROR: "; case fcf::NTest::LL_WRN: return "??? WARN: "; case fcf::NTest::LL_DBG: return "[DEBUG] "; default: return ""; } }; logger.appendPrefix(prefix); // 2. Log messages at different levels logger.err() << "Something went wrong!" << std::endl; logger.wrn() << "A minor issue occurred." << std::endl; logger.dbg() << "Debugging details..." << 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: "LevelDemo" -> "Logger" -> "SeverityTest" ... > !!! ERROR: Something went wrong! > ??? WARN: A minor issue occurred. [SUCCESS] Test completed successfully (0.000`013`461 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`013`461 sec