You may have code that usually writes to
std::cout, etc. but is lost in when using a test framework. This tip extracts some code from my article on using Gherkin DSL to show how a test frameworks' logging function can be wrapped and substituted into
std::cout, etc. to enhance the test log.
The content of LogStream.h is a class containing a buffer and two overloaded functions:
class LogStream : public std::streambuf
int_type overflow(int_type ch)
if (ch != traits_type::eof())
if (buffer.back() == '\n')
newBuffer = std::make_shared<TestUtils::LogStream>();
oldBuffer = std::clog.rdbuf(newBuffer.get());
std::clog << "Entering Tests" << std::endl;
std::clog << "Exiting Tests" << std::endl;
newBuffer = nullptr;
Mathematician turned freelance Software Engineer with over 20 years experience, mainly in the development of CAD/CAM/CAE software. Generally worked for smaller businesses - although have been at Lloyd's Register, Siemens and Rolls-Royce. Enjoy living on the edge of the Peak District where I go cycling and hiking.