Belle II Software development
|
Capture stdout and stderr and convert into log messages. More...
#include <IOIntercept.h>
Public Member Functions | |
OutputToLogMessages (const std::string &name, LogConfig::ELogLevel stdoutLevel, LogConfig::ELogLevel stderrLevel, int stdoutDebugLevel, int stderrDebugLevel) | |
Full constructor to choose the log levels and debug levels for both stdout and stderr. | |
OutputToLogMessages (const std::string &name, LogConfig::ELogLevel stdoutLevel, LogConfig::ELogLevel stderrLevel) | |
Constructor to choose the log levels both stdout and stderr. | |
OutputToLogMessages (const std::string &name) | |
Simple constructor which uses c_Info for output on stdout and c_Error for output on stderr. | |
~OutputToLogMessages () | |
Destructor to make sure that output is converted to messages on destruction. | |
void | setIndent (const std::string &indent) |
Set the indent for each line of the output, default is the supplied name + ": " | |
bool | finish () |
Finish the capture and emit the message if output has appeard on stdout or stderr. | |
bool | start () |
Start intercepting the output. | |
const std::string & | getStdOut () const |
Return the captured stdout output if any. | |
const std::string & | getStdErr () const |
Return the captured stderr output if any. | |
Private Attributes | |
const std::string | m_name |
Name of the output producing tool/library. | |
std::string | m_indent |
Identation to add to the beginning of each line of output. | |
LogConfig::ELogLevel | m_stdoutLevel |
severity of the log message to be emitted for output on stdout | |
LogConfig::ELogLevel | m_stderrLevel |
severity of the log message to be emitted for output on stderr | |
int | m_stdoutDebugLevel |
debug level for the log message to be emitted for output on stdout if m_stdoutLevel is c_Debug | |
int | m_stderrDebugLevel |
debug level for the log message to be emitted for output on stderr if m_stderrLevel is c_Debug | |
STDOUT | m_stdout {std::cout, stdout} |
StreamInterceptor for stdout. | |
STDERR | m_stderr {std::cerr, stderr} |
StreamInterceptor for stderr. | |
Capture stdout and stderr and convert into log messages.
This class can be used to convert output by a third party library into basf2 log messages.
For example
this will emit an ERROR message of the form
[ERROR] Output from external_library: external_library: this is my error
The leading indentation defaults to the name supplied on construction plus a colon and can be changed using the setIndent() member.
Definition at line 226 of file IOIntercept.h.
|
inline |
Full constructor to choose the log levels and debug levels for both stdout and stderr.
name | name of the code causing the output, for example "ROOT", "Rave", ... |
stdoutLevel | severity of the log message to be emitted for output on stdout |
stderrLevel | severity of the log message to be emitted for output on stderr |
stdoutDebugLevel | debug level for the log message to be emitted for output on stdout if stdoutLevel is c_Debug |
stderrDebugLevel | debug level for the log message to be emitted for output on stderr if stderrLevel is c_Debug |
Definition at line 235 of file IOIntercept.h.
|
inline |
Constructor to choose the log levels both stdout and stderr.
If the level is set to c_Debug a debug level of 100 is used.
name | name of the code causing the output, for example "ROOT", "Rave", ... |
stdoutLevel | severity of the log message to be emitted for output on stdout |
stderrLevel | severity of the log message to be emitted for output on stderr |
Definition at line 246 of file IOIntercept.h.
|
inlineexplicit |
Simple constructor which uses c_Info for output on stdout and c_Error for output on stderr.
name | name of the code causing the output, for example "ROOT", "Rave", ... |
Definition at line 252 of file IOIntercept.h.
|
inline |
Destructor to make sure that output is converted to messages on destruction.
Definition at line 255 of file IOIntercept.h.
bool finish | ( | ) |
Finish the capture and emit the message if output has appeard on stdout or stderr.
Definition at line 236 of file IOIntercept.cc.
|
inlineinherited |
Return the captured stderr output if any.
Only filled after finish() is called
Definition at line 166 of file IOIntercept.h.
|
inlineinherited |
Return the captured stdout output if any.
Only filled after finish() is called
Definition at line 160 of file IOIntercept.h.
|
inline |
Set the indent for each line of the output, default is the supplied name + ": "
Definition at line 257 of file IOIntercept.h.
|
inlineinherited |
Start intercepting the output.
This function can be called multiple times.
Definition at line 155 of file IOIntercept.h.
|
private |
Identation to add to the beginning of each line of output.
defaults to "${m_name}: "
Definition at line 264 of file IOIntercept.h.
|
private |
Name of the output producing tool/library.
Definition at line 262 of file IOIntercept.h.
|
privateinherited |
StreamInterceptor for stderr.
Definition at line 176 of file IOIntercept.h.
|
private |
debug level for the log message to be emitted for output on stderr if m_stderrLevel is c_Debug
Definition at line 272 of file IOIntercept.h.
|
private |
severity of the log message to be emitted for output on stderr
Definition at line 268 of file IOIntercept.h.
|
privateinherited |
StreamInterceptor for stdout.
Definition at line 174 of file IOIntercept.h.
|
private |
debug level for the log message to be emitted for output on stdout if m_stdoutLevel is c_Debug
Definition at line 270 of file IOIntercept.h.
|
private |
severity of the log message to be emitted for output on stdout
Definition at line 266 of file IOIntercept.h.