Belle II Software  release-08-01-10
Belle2::IOIntercept Namespace Reference

Encapsulate all classes needed to intercept stdout and stderr. More...

Classes

class  StreamInterceptor
 Base class with all necessary features to intercept output to a file descriptor. More...
 
class  KeepStream
 Dummy class which keeps the stream unmodified. More...
 
class  DiscardStream
 Simple class to just discard anything written to stream by redirecting it to /dev/null. More...
 
class  CaptureStream
 Class to capture anything written to stream into a string. More...
 
class  InterceptOutput
 Class to intercept stdout and stderr and either capture, discard or keep them unmodified depending on the template arguments. More...
 
class  OutputToLogMessages
 Capture stdout and stderr and convert into log messages. More...
 
class  InterceptorScopeGuard
 Simple RAII guard for output interceptor. More...
 
class  CaptureStreamAbortHandler
 Small class to handle std::abort() calls by external libraries. More...
 

Typedefs

using CaptureStdOutStdErr = InterceptOutput< CaptureStream, CaptureStream >
 Capture both stdout and stderr as strings.
 
using CaptureStdOut = InterceptOutput< CaptureStream, KeepStream >
 Capture only stdout and don't modify stderr.
 
using CaptureStdErr = InterceptOutput< KeepStream, CaptureStream >
 Capture only stderr and don't modify stdout.
 
using DiscardStdOutStdErr = InterceptOutput< DiscardStream, DiscardStream >
 Discard both stdout and stderr.
 
using DiscardStdOut = InterceptOutput< DiscardStream, KeepStream >
 Discard only stdout and don't modify stderr.
 
using DiscardStdErr = InterceptOutput< KeepStream, DiscardStream >
 Discard only stderr and don't modify stdout.
 
using CaptureStdOutDiscardStdErr = InterceptOutput< CaptureStream, DiscardStream >
 Capture stdout and discard stderr.
 
using DiscardStdOutCaptureStdErr = InterceptOutput< DiscardStream, CaptureStream >
 Capture stderr and discard stdout.
 

Functions

template<class T >
InterceptorScopeGuard< T > start_intercept (T &interceptor)
 Convenience wrapper to simplify use of InterceptorScopeGuard<T>. More...
 

Detailed Description

Encapsulate all classes needed to intercept stdout and stderr.

Function Documentation

◆ start_intercept()

InterceptorScopeGuard<T> Belle2::IOIntercept::start_intercept ( T &  interceptor)

Convenience wrapper to simplify use of InterceptorScopeGuard<T>.

This function will return the correct scope guard without the need to specify the template parameter.

IOIntercept::OutputToLogMessages iointercept("myinterceptor");
if(needIntercept){
auto guard = IOIntercept::start_intercept(iointercept);
// while the variable guard is in scope the intercept will be active
}
// intercept will be disabled here
InterceptorScopeGuard< T > start_intercept(T &interceptor)
Convenience wrapper to simplify use of InterceptorScopeGuard<T>.
Definition: IOIntercept.h:345
Parameters
interceptorthe interceptor object to use, must stay valid during the lifetime of the returned object.

Definition at line 345 of file IOIntercept.h.

346  {
347  return InterceptorScopeGuard<T> {interceptor};
348  }