|
MRPT
2.0.3
|
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 24 of file CConsoleRedirector.h.
#include <mrpt/system/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... | |
| ~CConsoleRedirector () override | |
| void | flush () |
| virtual void | writeString (const std::string &str) |
Protected Attributes | |
| std::ofstream | m_of |
| The text output file stream. More... | |
| std::streambuf * | sbOld = nullptr |
| The "old" std::cout. More... | |
| std::streambuf * | sbOld_cerr = nullptr |
| The "old" std::cout. More... | |
| bool | m_also_to_console |
| std::mutex | m_cs |
| std::vector< char > | m_buf |
Private Member Functions | |
| int | overflow (int c) override |
| int | sync () 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 49 of file CConsoleRedirector.h.
References m_buf, m_of, out, sbOld, sbOld_cerr, and THROW_EXCEPTION_FMT.
|
inlineoverride |
Definition at line 81 of file CConsoleRedirector.h.
References sbOld, sbOld_cerr, and sync().
|
inline |
Definition at line 89 of file CConsoleRedirector.h.
References sync().
|
inlineoverrideprivate |
Definition at line 97 of file CConsoleRedirector.h.
References m_cs, sync(), and writeString().
|
inlineoverrideprivate |
Definition at line 118 of file CConsoleRedirector.h.
References m_cs, and writeString().
Referenced by flush(), overflow(), and ~CConsoleRedirector().
|
inlinevirtual |
Definition at line 90 of file CConsoleRedirector.h.
References m_also_to_console, m_of, and sbOld.
Referenced by overflow(), and sync().
|
protected |
Definition at line 33 of file CConsoleRedirector.h.
Referenced by writeString().
|
protected |
Definition at line 35 of file CConsoleRedirector.h.
Referenced by CConsoleRedirector().
|
protected |
Definition at line 34 of file CConsoleRedirector.h.
Referenced by overflow(), and sync().
|
protected |
The text output file stream.
Definition at line 28 of file CConsoleRedirector.h.
Referenced by CConsoleRedirector(), and writeString().
|
protected |
The "old" std::cout.
Definition at line 30 of file CConsoleRedirector.h.
Referenced by CConsoleRedirector(), writeString(), and ~CConsoleRedirector().
|
protected |
The "old" std::cout.
Definition at line 32 of file CConsoleRedirector.h.
Referenced by CConsoleRedirector(), and ~CConsoleRedirector().
| Page generated by Doxygen 1.8.14 for MRPT 2.0.3 Git: 8e9e8af54 Wed May 13 17:41:24 2020 +0200 at miƩ may 13 17:55:54 CEST 2020 |