stream from class fcf::NTest::Logger::OutputTarget
Property: stream
Type:
Class:
Package: fcfTest
File: test.hpp
Available from version: 1.1.13
Pointer to the output stream where log messages will be written.
The
Example: Redirecting Logs to a File Stream
Demonstrating how to set the
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <fstream>
FCF_TEST_DEFINE ("StreamDemo", "Logger", "FileStreamTest") {
// 1. Create a file stream (static to ensure it lives long enough)
static std::ofstream logFile("test_output.log");
fcf::NTest::Logger & logger = fcf::NTest::logger ();
// 2. Create an OutputTarget
fcf::NTest::Logger::OutputTarget fileTarget;
fileTarget.name = "file_target";
// 3. Set the stream to our file stream
fileTarget.stream = &logFile;
// 4. Apply the target to the logger
logger.targets ({fileTarget});
fcf::NTest::log () << "This message goes to the file!" << std::endl;
FCF_TEST (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: "StreamDemo" -> "Logger" -> "FileStreamTest" ...
Check the file
> This message goes to the file!
[SUCCESS] Test completed successfully (0.000`063`874 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`063`874 sec
VPSDime is an industry leading VPS hosting company that provides virtualized server services with high performance, availability and friendly support.