Type:
class fcf::NTest::Logger::OutputTarget
Owner class: fcf::NTest::Logger
Package: fcfTest
File: test.hpp
Available from version: 1.1.13
A structure representing a specific output destination for log messages, including the stream, name, and associated formatting settings.
The fcf::NTest::Logger::OutputTarget structure defines where and how log messages should be written. It encapsulates a pointer to an output stream (such as std::cout or a file stream), a unique name for the target, and specific formatting rules. Each target can have its own unique set of fcf::NTest::Logger::Prefix and fcf::NTest::Logger::Format configurations, allowing the logger to output different information to different destinations simultaneously (e.g., a detailed log to a file and a simplified summary to the console).
Properties
- A unique identifier for the output target.
- Pointer to the output stream where log messages will be written.
- The name of the format to be used for this specific target.
- A map containing persistent data associated with the prefixes of this target.
- A map containing persistent data associated with the formatters of this target.
Example: Configuring Multiple Output Targets
Demonstrating how to manually create and configure multiple fcf::NTest::Logger::OutputTarget instances to direct logs to both the console and a file with different formats.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
#include <fstream>
FCF_TEST_DEFINE("MultiTarget", "Logger", "TargetDemo") {
FCF_TEST(true);
}
int main(int a_argc, char* a_argv[]) {
fcf::NTest::Logger& logger = fcf::NTest::logger();
// 1. Create a target for the standard console output
fcf::NTest::Logger::OutputTarget consoleTarget;
consoleTarget.name = "console";
consoleTarget.stream = &std::cout;
consoleTarget.format = "default";
// 2. Create a target for a log file with JUnit XML format
// We use a local file stream for this demonstration
static std::ofstream fileStream("test_results.xml");
fcf::NTest::Logger::OutputTarget fileTarget;
fileTarget.name = "junit-file";
fileTarget.stream = &fileStream;
fileTarget.format = "junit";
// 3. Clear existing targets and add our new ones
logger.targets({consoleTarget, fileTarget});
bool error = false;
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "MultiTarget" -> "Logger" -> "TargetDemo" ...
[SUCCESS] Test completed successfully (0.000`000`333 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`000`333 sec
test_results.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failure="0" skipped="0" time="0.000000333">
<testsuite name="MultiTarget/Logger" tests="1" failure="0" skipped="0" time="0.000000333">
<testcase classname="MultiTarget/Logger" name="TargetDemo" time="0.000000333"/>
</testsuite>
</testsuites>
In this example, the fcf::NTest::Logger::OutputTarget::format property was used to specify different output styles for the console and the file simultaneously.