Type:
class fcf::NTest::LogWriter
Package: fcfTest
File: test.hpp
Available from version: 1.1.1
An RAII-based stream wrapper used for buffering log messages before they are dispatched to the central Logger.
The fcf::NTest::LogWriter class acts as a temporary buffer for log messages. It implements the RAII (Resource Acquisition Is Initialization) pattern: when a fcf::NTest::LogWriter object is created (for example, via global shortcuts like fcf::NTest::inf()), it captures all data sent through the stream operator operator<<. Upon the object's destruction, the accumulated message is automatically dispatched to the fcf::NTest::Logger according to the current logging configuration and levels.
This design allows for efficient, thread-safe, and atomic logging of complex, multi-part messages.
Methods
template <typename Ty> fcf::NTest::LogWriter&
operator<<(
const Ty& a_value)
template <typename Ty> fcf::NTest::LogWriter&
operator<<(
std::ostream& (*a_manipulator)(std::ostream&))
- Appends a value of any type to the internal log buffer using the standard stream insertion operator.
Example: RAII Logging Workflow
Demonstration of how LogWriter works behind the scenes when using global logging shortcuts.
#define FCF_TEST_IMPLEMENTATION
#include <fcfTest/test.hpp>
#include <iostream>
FCF_TEST_DECLARE("LogDemo", "Usage", "LogWriterFlow") {
// The following line calls fcf::NTest::inf(), which returns a temporary fcf::NTest::LogWriter object.
// The message is buffered in the object's internal stringstream.
// When the statement ends, the temporary object is destroyed, and the message is sent to the logger.
fcf::NTest::log() << "This is a single-line log message." << std::endl;
// Demonstrating multi-line buffering within a single statement.
// The LogWriter object lives until the end of this expression.
fcf::NTest::err() << "Error occurred!" << " Code: " << 404 << std::endl;
}
int main(int a_argc, char* a_argv[]) {
bool error = false;
// Run the tests to see the LogWriter in action
fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error);
return error ? 1 : 0;
}
Output:
Performing the test: "LogDemo" -> "Usage" -> "LogWriterFlow" ...
> This is a single-line log message.
> Error occurred! Code: 404
[SUCCESS] Test completed successfully (0.000`023`535 sec)
[SUCCESS] All tests were completed.
Tests: 1 passed, 0 failed, 0 skipped, 1 total
Duration: 0.000`023`535 sec