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

stream from class fcf::NTest::Logger::OutputTarget

Property: stream

Type: std::ostream*

Class: fcf::NTest::Logger::OutputTarget

Package: fcfTest

File: test.hpp

Available from version: 1.1.13

Pointer to the output stream where log messages will be written.

The stream property is a pointer to a std::ostream object. It defines the physical destination of the log output. If this pointer is null, the logger will default to using std::cout for this target.

Example: Redirecting Logs to a File Stream

Demonstrating how to set the stream property to a file stream to save logs to a disk.

#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 test_output.log to see the logged message.

test_output.log 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