origin from class fcf::NTest::Logger::MessageContext
Property: origin
Type:
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.1.14
Contains the original message string
The
Example: Accessing Origin in Prefix
Demonstrating how to use the
#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
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.