Closed bstordrup closed 6 months ago
can you point to where the bug in the library is that is causing the issue, as opposed to an issue with how you're redirecting the various streaming buffers?
Updated the issue to more precisely describe the problem.
There are two places in code that contributes to this error:
console_reporter.cc
, there is a check on the output stream where std::cout is directly compared to GetOutputStream(), and if different, the "Color printing is only supported..." is reported.ColorPrintf (std::ostream& out, LogColor color, const char* fmt, va_list args)
method operates directly on stdout
for flushing the stream and uses vprintf
to make the actual output.I have a branch in my local fork with changes in these two places that makes color printing work in a Console window created with AllocConsole
.
ah great, thank you for the clarification! :)
Describe the bug I use
benchmark.dll
inside a non-console application because I want to benchmark different implementations of ways to solve the same problem. And it is not possible to extract the code into a separate project, as the benchmarked code calls several other functions.Therefore, I rolled my own BenchmarkMain method that does the same as BENCHMARK_MAIN macro, but also creates a console with
AllocConsole
, createsstd::ostream
instances forSTD_OUTPUT_HANDLE
andSTD_ERROR_HANDLE
, creates aConsoleReporter
instance and callsRunSpecificBenchmarks
with this displayReporter.The console did receive output, but it reported that Color printing was only supported on Windows - which makes no sense as the console being written to is on Windows.
Along the way, the
std::cout.rdbuf()
is saved, and replaced with the the same.rdbuf()
that is used for thestd::ostream out
instance.System
To reproduce Inside a non-console application, add the following function:
Make sure that the function is being called when the application starts - I control this with a command line parameter.
Note that the output written to the console is without any color formatting.
Expected behavior Output from benchmarking should get color-enabled output in the created console window
Additional context The application, where I call the benchmark library, is a MFC Windows application created with use of an external library (CodeJock).