-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture stdout and redirect to plog #274
Comments
Hi @Ry-Kode ! Could you give some more details? As there could be different solutions. |
Hello Sergius, I'm not qutie sure what kind of details I can provide. Let me explain my use case: in my project I'm using your PLOG lib (thanks again for this!!) to create a rolling logfile. I'm also using some third party libraries which generate output that is written to stderr (and sometimes stdout). I'm looking for a way to 'capture' this output and save it to the PLOG rolling log file. Thank you |
Can you recompile those libraries? |
So you can just add |
Yes, that would be one option. |
Hello Sergius, |
@Ry-Kode Are they static libs (.lib) or dynamic libs (.dll)? |
Static libs (.lib) |
You can try the following approach: union
{
struct
{
int readPipe;
int writePipe;
};
int pipeHandles[2];
} pipes;
_pipe(pipes.pipeHandles, 0, O_TEXT);
_dup2(pipes.writePipe, _fileno(stderr));
auto pipeFuture = std::async(launch::async, [&]()
{
std::array<char, 0x800> buf{};
for(;;)
{
int bytesRead = _read(pipes.readPipe, buf.data(), static_cast<int>(buf.size()));
if (bytesRead <= 0)
{
break;
}
buf[bytesRead] = 0;
LOGV << buf.data();
}
});
std::cerr << "test test";
_close(pipes.writePipe);
_close(_fileno(stderr)); It may work for your setup. But there is no guarantee. |
Thank you for the snippet Sergius. |
Posix is the same, just without the underscore. |
Hello,
Would it be possibe to redirect stderr so that stuff written to stderr is written to the log?
Thanks!
The text was updated successfully, but these errors were encountered: