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

line from class fcf::NTest::Logger::MessageContext

Property: line

Type: size_t

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

Package: fcfTest

File: test.hpp

Available from version: 1.1.14

The line number within the message where the current prefix is being applied.

The line property tracks the current line index of the message being processed. This is particularly useful for multi-line messages, as it allows fcf::NTest::Logger::Prefix handlers to apply different prefixes to each subsequent line of the same log entry.

Example: Multi-line Prefixing

Demonstrating how to use the line property to apply a different prefix to the first line versus subsequent lines of a multi-line message.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("LineDemo", "Logger", "MultiLinePrefix") { fcf::NTest::Logger& logger = fcf::NTest::logger(); // 1. Register a functional prefix that reacts to the line number fcf::NTest::Logger::Prefix prefix; prefix.name = "line-prefix"; prefix.multiLine = true; prefix.category = fcf::NTest::LMC_ALL; prefix.handler = []( fcf::NTest::Logger& logger, fcf::NTest::Logger::MessageContext& context) { if (context.line == 0) { return "[START] "; } else { return " [CONT] "; } }; logger.appendPrefix(prefix); // 2. Log a multi-line message logger.log() << "First line\nSecond line\nThird line" << 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: "LineDemo" -> "Logger" -> "MultiLinePrefix" ... > [START] First line > [CONT] Second line > [CONT] Third line [SUCCESS] Test completed successfully (0.000`009`664 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`009`664 sec