I have a command-line option to control whether the listener writes to the file, but it always prints the SUCCEED messages because that's rather important for the way we use that macro in our test code.
It sounds like it would be simpler if you put the enable/disable logic within your tests.
The relevant code from my listener is extremely simple:
void FilePrinter::OnTestPartResult(const TestPartResult& result)
{
std::string part = FormatTestPartResult(result);
// calls to SUCCEED() should also go to stdout
if(result.type() == TestPartResult::kSuccess)
printf("%s\n", part.c_str());
logger.writeToFile(part);
}
The FormatTestPartResult method just returns a string containing the same information as the default test output with some extra line breaks and a timestamp. I think that I copied most of it from the gtest code for printing test results.