13#include <framework/logging/LogConfig.h>
21 namespace IOIntercept {
59 static void readFD(
int fd, std::string& out);
82 bool start()
const {
return true; }
150 template<
class STDOUT,
class STDERR>
162 static_assert(std::is_same<STDOUT, CaptureStream>::value,
"Only valid if stdout is captured using CaptureStream");
168 static_assert(std::is_same<STDERR, CaptureStream>::value,
"Only valid if stderr is captured using CaptureStream");
236 int stdoutDebugLevel,
int stderrDebugLevel):
314 b.m_interceptor =
nullptr;
Small class to handle std::abort() calls by external libraries.
Class to capture anything written to stream into a string.
std::string m_outputStr
string with the output, only filled after finish()
const std::string & getOutput() const
Get the output, only set after finish()
int m_pipeReadFD
file descriptor of the read end of the pipe
bool start()
Start intercepting the output.
~CaptureStream()
Close file descriptors.
bool finish()
Restore the stream and get the output from the pipe.
Simple class to just discard anything written to stream by redirecting it to /dev/null.
Class to intercept stdout and stderr and either capture, discard or keep them unmodified depending on...
STDOUT m_stdout
StreamInterceptor for stdout.
STDERR m_stderr
StreamInterceptor for stderr.
const std::string & getStdOut() const
Return the captured stdout output if any.
bool start()
Start intercepting the output.
bool finish()
Finish intercepting the output.
const std::string & getStdErr() const
Return the captured stderr output if any.
Simple RAII guard for output interceptor.
InterceptorScopeGuard(InterceptorScopeGuard< T > &&b)
Move constructor which will take over the interception state.
~InterceptorScopeGuard()
Finish interception on cleanup.
InterceptorScopeGuard(const InterceptorScopeGuard< T > &)=delete
We don't want copying.
InterceptorScopeGuard(T &interceptor)
Construct a new instance for a given interceptor object and start intercepting io.
InterceptorScopeGuard & operator=(const InterceptorScopeGuard &)=delete
Also no assignment.
T * m_interceptor
pointer to the interceptor we guard
Dummy class which keeps the stream unmodified.
KeepStream(std::ostream &, FILE *)
This class is basically empty so the constructor does nothing.
bool start() const
doing nothing always succeds
bool finish() const
doing nothing always succeds
Capture stdout and stderr and convert into log messages.
OutputToLogMessages(const std::string &name)
Simple constructor which uses c_Info for output on stdout and c_Error for output on stderr.
LogConfig::ELogLevel m_stderrLevel
severity of the log message to be emitted for output on stderr
OutputToLogMessages(const std::string &name, LogConfig::ELogLevel stdoutLevel, LogConfig::ELogLevel stderrLevel)
Constructor to choose the log levels both stdout and stderr.
const std::string m_name
Name of the output producing tool/library.
int m_stderrDebugLevel
debug level for the log message to be emitted for output on stderr if m_stderrLevel is c_Debug
void setIndent(const std::string &indent)
Set the indent for each line of the output, default is the supplied name + ": "
~OutputToLogMessages()
Destructor to make sure that output is converted to messages on destruction.
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.
LogConfig::ELogLevel m_stdoutLevel
severity of the log message to be emitted for output on stdout
bool finish()
Finish the capture and emit the message if output has appeard on stdout or stderr.
int m_stdoutDebugLevel
debug level for the log message to be emitted for output on stdout if m_stdoutLevel is c_Debug
std::string m_indent
Identation to add to the beginning of each line of output.
Base class with all necessary features to intercept output to a file descriptor.
static void readFD(int fd, std::string &out)
Read the contents of a file descriptor until there is no more input and place them in out.
std::ostream & m_stream
C++ stream object, only needed to flush before replacement.
bool replaceFD(int fileDescriptor)
Replace the file descriptor of m_fileObject with the one passed.
~StreamInterceptor()
close file descriptors
FILE * m_fileObject
File object of the file we want to replace, needed to obtain file descriptor and to flush.
void setReplacementFD(int fd)
set the replacement file descriptor, should be called in the constructor of derived classes
bool start()
start intercepting the stream.
int m_replacementFD
Replacement file descriptor to be used while capturing.
int m_savedFD
Saved file descriptor: a duplicate of the file descriptor of m_fileObject.
bool finish()
stop intercepting the stream.
bool m_capturing
Check whether we are already capturing.
ELogLevel
Definition of the supported log levels.
InterceptorScopeGuard< T > start_intercept(T &interceptor)
Convenience wrapper to simplify use of InterceptorScopeGuard<T>.
Abstract base class for different kinds of events.