Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::PseudoLogStream Class Reference

Stream-based log message builder for the MITK log mechanism. More...

#include <mitkLog.h>

Collaboration diagram for mitk::PseudoLogStream:

Public Member Functions

 PseudoLogStream (LogLevel level, const std::string &filePath, int lineNumber, const std::string &functionName)
 Construct a log stream for a message at the given level and source location. More...
 
 ~PseudoLogStream ()
 Destructor that distributes the assembled log message to all backends. More...
 
template<class T >
PseudoLogStream & operator<< (const T &data)
 Stream data into the log message (const reference overload). More...
 
template<class T >
PseudoLogStream & operator<< (T &data)
 Stream data into the log message (non-const reference overload). More...
 
PseudoLogStream & operator<< (std::ostream &(*func)(std::ostream &))
 Stream manipulator overload (e.g. std::endl, std::flush). More...
 
PseudoLogStream & operator() (const std::string &category)
 Set or append a category for this log message. More...
 
PseudoLogStream & operator() (bool enabled)
 Conditionally enable or disable this log stream. More...
 

Protected Attributes

bool m_Disabled
 
LogMessage m_Message
 
std::stringstream m_Stream
 

Detailed Description

Stream-based log message builder for the MITK log mechanism.

Provides an std::ostream-like interface for constructing log messages. Data streamed via operator<< is accumulated in an internal string stream. Upon destruction, the assembled message is distributed to all registered and enabled backends via DistributeToBackends().

All streaming operations use the "C" locale to ensure consistent numeric formatting regardless of the application's locale settings.

This class should not be instantiated directly. Use the convenience macros MITK_INFO, MITK_WARN, MITK_ERROR, MITK_FATAL, and MITK_DEBUG instead.

Example:

MITK_INFO << "Processing image " << imageIndex << " of " << totalImages;
MITK_WARN("myCategory") << "Unexpected value: " << value;
MITK_DEBUG(verbose) << "Detailed debug output";
#define MITK_INFO
Log an informational message.
Definition: mitkLog.h:358
#define MITK_WARN
Log a warning message.
Definition: mitkLog.h:365
#define MITK_DEBUG
Definition: mitkLog.h:390
See also
NullLogStream, LogMessage, DistributeToBackends()

Definition at line 136 of file mitkLog.h.

Constructor & Destructor Documentation

◆ PseudoLogStream()

mitk::PseudoLogStream::PseudoLogStream ( LogLevel  level,
const std::string &  filePath,
int  lineNumber,
const std::string &  functionName 
)
inline

Construct a log stream for a message at the given level and source location.

Parameters
[in]levelSeverity level of the log message.
[in]filePathSource file path (typically FILE).
[in]lineNumberSource line number (typically LINE).
[in]functionNameSource function name (typically FUNCTION).

Definition at line 146 of file mitkLog.h.

◆ ~PseudoLogStream()

mitk::PseudoLogStream::~PseudoLogStream ( )
inline

Destructor that distributes the assembled log message to all backends.

If the stream has not been disabled, the accumulated message text and the module name (from MITKLOG_MODULENAME) are set on the internal LogMessage, which is then passed to DistributeToBackends().

Definition at line 159 of file mitkLog.h.

References mitk::DistributeToBackends(), and MITKLOG_MODULENAME.

Member Function Documentation

◆ operator()() [1/2]

PseudoLogStream& mitk::PseudoLogStream::operator() ( bool  enabled)
inline

Conditionally enable or disable this log stream.

When called with false, the stream is disabled: all subsequent streaming operations become no-ops and the message will not be distributed to backends. Once disabled, the stream cannot be re-enabled.

Parameters
[in]enabledIf false, disables this stream. If true, no effect (the stream remains in its current state).
Returns
Reference to this stream for chaining.

Example:

MITK_INFO(verbose) << "This is only logged when verbose is true";

Definition at line 290 of file mitkLog.h.

◆ operator()() [2/2]

PseudoLogStream& mitk::PseudoLogStream::operator() ( const std::string &  category)
inline

Set or append a category for this log message.

Categories help organize log output by topic or subsystem. If a category has already been set, the new category is appended with a dot separator (e.g. calling with "a" then "b" yields "a.b").

If the stream is disabled, this is a no-op.

Parameters
[in]categoryThe category string to set or append.
Returns
Reference to this stream for chaining.

Example:

MITK_INFO("io")("dicom") << "Loading DICOM file";
// Category will be "io.dicom"

Definition at line 262 of file mitkLog.h.

◆ operator<<() [1/3]

template<class T >
PseudoLogStream& mitk::PseudoLogStream::operator<< ( const T &  data)
inline

Stream data into the log message (const reference overload).

Appends the string representation of data to the internal message stream using the "C" locale. If the stream is disabled, this is a no-op.

Template Parameters
TType of the data to stream. Must support operator<< with std::ostream.
Parameters
[in]dataThe data to append to the log message.
Returns
Reference to this stream for chaining.

Definition at line 179 of file mitkLog.h.

◆ operator<<() [2/3]

PseudoLogStream& mitk::PseudoLogStream::operator<< ( std::ostream &(*)(std::ostream &)  func)
inline

Stream manipulator overload (e.g. std::endl, std::flush).

Applies the given stream manipulator to the internal message stream. If the stream is disabled, this is a no-op.

Parameters
[in]funcA stream manipulator function (e.g. std::endl).
Returns
Reference to this stream for chaining.

Definition at line 229 of file mitkLog.h.

◆ operator<<() [3/3]

template<class T >
PseudoLogStream& mitk::PseudoLogStream::operator<< ( T &  data)
inline

Stream data into the log message (non-const reference overload).

Appends the string representation of data to the internal message stream using the "C" locale. If the stream is disabled, this is a no-op.

Template Parameters
TType of the data to stream. Must support operator<< with std::ostream.
Parameters
[in]dataThe data to append to the log message.
Returns
Reference to this stream for chaining.

Definition at line 205 of file mitkLog.h.

Member Data Documentation

◆ m_Disabled

bool mitk::PseudoLogStream::m_Disabled
protected

Definition at line 297 of file mitkLog.h.

◆ m_Message

LogMessage mitk::PseudoLogStream::m_Message
protected

Definition at line 298 of file mitkLog.h.

◆ m_Stream

std::stringstream mitk::PseudoLogStream::m_Stream
protected

Definition at line 299 of file mitkLog.h.


The documentation for this class was generated from the following file: