I am using a dll that is outputting valuable debugging information, but I don't know how to view it since it isn't printed in the output log. I would like to know if there is some workaround so I can view whats being written to stdout and stderr.
Asked
Active
Viewed 1,394 times
1
-
this looks promising https://wiki.unrealengine.com/Use_std::cout_with_Unreal_Engine_Editor – JohnFilleau Feb 28 '20 at 05:13
-
Can you check the event log of system? – Build Succeeded Feb 28 '20 at 09:31
-
@John That unfortunately doesn't work because the program in question writes to stdout through printf. I should have clarified that though. – J. Rehbein Feb 29 '20 at 04:17
-
This gives instructions on how to redirect `stdout` to a file. I'm too sleepy to link that to unreal's stream in my head, but would the file output get you what you need? https://stackoverflow.com/questions/4810516/c-redirecting-stdout – JohnFilleau Feb 29 '20 at 04:21
-
@John I'm not sure which answer you're talking about, but the top one mentions how his solution only works for cout not stdout in general. I've seen that you can use freopen though and redirect the output to a file which should work well enough for my situation. – J. Rehbein Feb 29 '20 at 04:31
-
The top answer. They redirect to `/dev/null`, but redirecting to an actual file should be the same process. – JohnFilleau Feb 29 '20 at 04:32
1 Answers
1
It's actually pretty easy (even though there is very few places explaining how).
Idea: Inherit std::stringbuf
to make it use UE_LOG
and then feed an instance of that inherited class to std::cout
. E.g., something like this:
Inherited class
#include <sstream>
class LStream : public std::stringbuf{
protected:
int sync() {
UE_LOG(LogTemp, Log, TEXT("%s"), *FString(str().c_str()));
str("");
return std::stringbuf::sync();
}
};
Telling std::cout
to use LStream
LStream Stream;
std::cout.rdbuf(&Stream);
std::cout << "some message" << std::endl;
Sources:

Ginés Hidalgo
- 717
- 9
- 20