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

origin from class fcf::NTest::Logger::MessageContext

Property: origin

Type: std::string

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

Package: fcfTest

File: test.hpp

Available from version: 1.1.14

Contains the original message string

The origin property contains the string representation of the message's source. In the context of assertions, this typically holds the failing expression. In the context of general logging, it can be used to identify the component or module that generated the log.

Example: Accessing Origin in Prefix

Demonstrating how to use the origin property to highlight the source of a log message in a custom prefix.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> enum { MY_CUSTOM_MESSAGE = fcf::NTest::LMC_USER_GROUP | 0x0001 }; FCF_TEST_DEFINE("OriginDemo", "Logger", "OriginTest") { // 1. Register a functional prefix that uses the origin string fcf::NTest::Logger::Prefix prefix; prefix.name = "origin-prefix"; prefix.multiLine = false; prefix.category = MY_CUSTOM_MESSAGE; prefix.handler = []( fcf::NTest::Logger& a_logger, fcf::NTest::Logger::MessageContext& a_context) { if (!a_context.origin.empty()) { std::string origin = a_context.origin; origin.erase(origin.find_last_not_of(" \t\n\r\f\v") + 1); return std::string() + "(" + origin + "): "; } return std::string(""); }; fcf::NTest::logger().appendPrefix(prefix); // 2. Log a message with a specific origin // Note: In standard logging, origin is often the message itself if not specified otherwise fcf::NTest::log(MY_CUSTOM_MESSAGE) << "Standard log message" << std::endl; } 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: "OriginDemo" -> "Logger" -> "OriginTest" ... > (Standard log message): Standard log message [SUCCESS] Test completed successfully (0.000`007`940 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`007`940 sec