RAII guard that temporarily removes an attached 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.
- Note
- The guard acts only on a stream that is attached when it is constructed; for an unattached stream it does nothing (will not insert on scope exit). On a thread-local stream, it suppresses the stream for the calling thread until it ends, also if the global stream inserts it again meanwhile; then the thread-local stream has the destinations it would have without the guard (e.g. not a destination that the global stream removed meanwhile). On a global stream, it removes the destination and inserts it again, with its prefix, at the end (unless it was inserted again meanwhile); the stream must outlive the guard.
-
The OPENMS_LOG_* macros write to thread-local streams that follow the destinations of the global ones. Guarding a global stream (getGlobalLog*()) suppresses the sink for all threads; guarding a thread-local stream (getThreadLocalLog*()) only for the calling thread. Text pending before and inside the guarded scope goes to the destinations it was written for: for a global stream, this holds for the calling thread, not for other threads.
Example usage:
some_operation_that_may_throw();
RAII guard that temporarily removes an attached stream from a LogStream and re-inserts it on scope ex...
Definition LogStream.h:579
Logger::LogStream & getThreadLocalLogInfo()
Get thread-local info log stream.