By creating an object of this class, all the output to std::cout (and std::cerr) will be redirected to a text file, and optionally also shown on the console.
Based on code from http://www.devmaster.net/forums/showthread.php?t=7037
Definition at line 27 of file CConsoleRedirector.h.
#include <mrpt/utils/CConsoleRedirector.h>
Public Member Functions | |
CConsoleRedirector (const std::string &out_file, bool also_to_console=true, bool also_cerr=true, bool append_file=false, int bufferSize=1000) | |
Constructor. More... | |
virtual | ~CConsoleRedirector () |
void | flush () |
virtual void | writeString (const std::string &str) |
Protected Attributes | |
std::ofstream | m_of |
The text output file stream. More... | |
std::streambuf * | sbOld |
The "old" std::cout. More... | |
std::streambuf * | sbOld_cerr |
The "old" std::cout. More... | |
bool | m_also_to_console |
mrpt::synch::CCriticalSection | m_cs |
Private Member Functions | |
int | overflow (int c) MRPT_OVERRIDE |
int | sync () MRPT_OVERRIDE |
|
inline |
Constructor.
out_file | The file to create / append |
also_to_console | Whether to redirect data to file and also dump data to the console as usual. |
append_file | If set to false the file will be truncated on open |
bufferSize | It's recommended to buffer the data instead of writing characters one by one. |
also_cerr | Whether to redirect the output to std::cerr in addition to std::cout. |
std::exception | If the file cannot be opened. |
Definition at line 45 of file CConsoleRedirector.h.
References THROW_EXCEPTION_FMT.
|
inlinevirtual |
Definition at line 77 of file CConsoleRedirector.h.
|
inline |
Definition at line 86 of file CConsoleRedirector.h.
|
inlineprivate |
Definition at line 98 of file CConsoleRedirector.h.
References mrpt::synch::CCriticalSection::enter(), and mrpt::synch::CCriticalSection::leave().
|
inlineprivate |
Definition at line 119 of file CConsoleRedirector.h.
References mrpt::synch::CCriticalSection::enter(), and mrpt::synch::CCriticalSection::leave().
|
inlinevirtual |
Definition at line 91 of file CConsoleRedirector.h.
|
protected |
Definition at line 33 of file CConsoleRedirector.h.
|
protected |
Definition at line 34 of file CConsoleRedirector.h.
|
protected |
The text output file stream.
Definition at line 30 of file CConsoleRedirector.h.
|
protected |
The "old" std::cout.
Definition at line 31 of file CConsoleRedirector.h.
|
protected |
The "old" std::cout.
Definition at line 32 of file CConsoleRedirector.h.
Page generated by Doxygen 1.8.14 for MRPT 1.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019 |