OpenMS
Loading...
Searching...
No Matches
LogSinkGuard Class Reference

RAII guard that temporarily removes a stream from a LogStream and re-inserts it on scope exit. More...

#include <OpenMS/CONCEPT/LogStream.h>

Collaboration diagram for LogSinkGuard:
[legend]

Public Member Functions

 LogSinkGuard (LogStream &log_stream, std::ostream &stream)
 Construct a guard that removes the stream and re-inserts it on destruction.
 
 ~LogSinkGuard ()
 Destructor re-inserts the stream.
 
 LogSinkGuard (const LogSinkGuard &)=delete
 
LogSinkGuardoperator= (const LogSinkGuard &)=delete
 
 LogSinkGuard (LogSinkGuard &&)=delete
 
LogSinkGuardoperator= (LogSinkGuard &&)=delete
 

Private Attributes

LogStreamlog_stream_
 
std::ostream & stream_
 

Detailed Description

RAII guard that temporarily removes a stream from a LogStream and re-inserts it on scope exit.

This class provides exception-safe temporary removal of output streams from LogStream objects. Use this when you need to temporarily suppress logging to a specific stream (e.g., cout) during operations that may throw exceptions.

Example usage:

LogSinkGuard guard(getGlobalLogInfo(), cout); // Removes cout, will re-insert on scope exit
some_operation_that_may_throw();
// cout is automatically re-inserted when guard goes out of scope
RAII guard that temporarily removes a stream from a LogStream and re-inserts it on scope exit.
Definition LogStream.h:475
Logger::LogStream & getGlobalLogInfo()
Get the global info log stream for configuration purposes.

Constructor & Destructor Documentation

◆ LogSinkGuard() [1/3]

LogSinkGuard ( LogStream log_stream,
std::ostream &  stream 
)
inline

Construct a guard that removes the stream and re-inserts it on destruction.

Parameters
log_streamThe LogStream to remove the stream from (and re-insert into on destruction)
streamThe stream to temporarily remove (e.g., std::cout)

◆ ~LogSinkGuard()

~LogSinkGuard ( )
inline

Destructor re-inserts the stream.

◆ LogSinkGuard() [2/3]

LogSinkGuard ( const LogSinkGuard )
delete

◆ LogSinkGuard() [3/3]

LogSinkGuard ( LogSinkGuard &&  )
delete

Member Function Documentation

◆ operator=() [1/2]

LogSinkGuard & operator= ( const LogSinkGuard )
delete

◆ operator=() [2/2]

LogSinkGuard & operator= ( LogSinkGuard &&  )
delete

Member Data Documentation

◆ log_stream_

LogStream& log_stream_
private

◆ stream_

std::ostream& stream_
private