line from class fcf::NTest::Logger::MessageContext
Property: line
Type:
Class:
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
Example: Multi-line Prefixing
Demonstrating how to use the
#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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.