Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
mitk::LogBackendText Class Referenceabstract

Abstract superclass for text-based log backends. More...

#include <mitkLogBackendText.h>

Inheritance diagram for mitk::LogBackendText:
Collaboration diagram for mitk::LogBackendText:

Public Member Functions

 ~LogBackendText () override
 
void ProcessMessage (const LogMessage &message) override=0
 Process a log message. More...
 
- Public Member Functions inherited from mitk::LogBackendBase
virtual ~LogBackendBase ()
 
virtual OutputType GetOutputType () const =0
 Return the output type of this backend. More...
 

Protected Member Functions

void FormatSmart (const LogMessage &message, int threadID=0)
 Format the given message in smart/short format and write it to std::cout. More...
 
void FormatFull (const LogMessage &message, int threadID=0)
 Format the given message in full/long format and write it to std::cout. More...
 
void FormatSmart (std::ostream &out, const LogMessage &message, int threadID=0)
 Format the given message in smart/short format and write it to the given stream. More...
 
void FormatFull (std::ostream &out, const LogMessage &message, int threadID=0)
 Format the given message in full/long format and write it to the given stream. More...
 
void AppendTimeStamp (std::ostream &out)
 Append the current wall-clock time to the given stream. More...
 
void FormatSmartWindows (const LogMessage &message, int threadID)
 Format a message in smart/short format with colored Windows console output. More...
 

Additional Inherited Members

- Public Types inherited from mitk::LogBackendBase
enum class  OutputType { Console , File , Other }
 Classification of the output destination of a backend. More...
 

Detailed Description

Abstract superclass for text-based log backends.

Provides two formatting modes for log messages that subclasses can use:

  • Smart/short format: Compact output with a relative timestamp (seconds since process start), optional category, log level prefix (for non-Info levels), and the message text. On Windows, this format uses colored console output. Level indicators: [] for Info, !! for Warn, ## for Error, ** for Fatal, {} for Debug.
  • Full/long format: Verbose pipe-delimited output containing the log level name, absolute timestamp, file path, line number, function name, thread ID, module name, category, and message text. Suitable for machine-readable log analysis.

Subclasses must implement ProcessMessage() and typically delegate to one of the Format methods.

See also
LogBackendCout, LogBackendBase

Definition at line 39 of file mitkLogBackendText.h.

Constructor & Destructor Documentation

◆ ~LogBackendText()

mitk::LogBackendText::~LogBackendText ( )
override

Member Function Documentation

◆ AppendTimeStamp()

void mitk::LogBackendText::AppendTimeStamp ( std::ostream &  out)
protected

Append the current wall-clock time to the given stream.

Writes the result of ctime() (with trailing newline replaced by a space) to the stream using the "C" locale.

Parameters
[out]outThe output stream to append the timestamp to.

◆ FormatFull() [1/2]

void mitk::LogBackendText::FormatFull ( const LogMessage &  message,
int  threadID = 0 
)
protected

Format the given message in full/long format and write it to std::cout.

Delegates to FormatFull(std::ostream&, ...) with std::cout.

Parameters
[in]messageThe log message to format and output.
[in]threadIDOptional thread ID where the message was emitted. Defaults to 0. Written as a hexadecimal value in the output.

◆ FormatFull() [2/2]

void mitk::LogBackendText::FormatFull ( std::ostream &  out,
const LogMessage &  message,
int  threadID = 0 
)
protected

Format the given message in full/long format and write it to the given stream.

Output format (pipe-delimited): LEVEL|timestamp||filePath(lineNumber)|functionName|threadID_hex|moduleName|category message

Parameters
[out]outThe output stream to write the formatted message to.
[in]messageThe log message to format.
[in]threadIDOptional thread ID. Written as hexadecimal. Defaults to 0.

◆ FormatSmart() [1/2]

void mitk::LogBackendText::FormatSmart ( const LogMessage &  message,
int  threadID = 0 
)
protected

Format the given message in smart/short format and write it to std::cout.

On Windows, this delegates to FormatSmartWindows() for colored console output. On other platforms, it delegates to FormatSmart(std::ostream&, ...) with std::cout.

On the very first call, the current wall-clock time is printed as a reference timestamp.

Parameters
[in]messageThe log message to format and output.
[in]threadIDOptional thread ID where the message was emitted. Defaults to 0 (unused in smart format output).

◆ FormatSmart() [2/2]

void mitk::LogBackendText::FormatSmart ( std::ostream &  out,
const LogMessage &  message,
int  threadID = 0 
)
protected

Format the given message in smart/short format and write it to the given stream.

Output format: {open_char}{relative_time}{close_char} [category] LEVEL: message

The opening and closing characters vary by log level (e.g. [] for Info, !! for Warn). On the very first invocation, the current wall-clock time is written as a reference line.

Parameters
[out]outThe output stream to write the formatted message to.
[in]messageThe log message to format.
[in]threadIDOptional thread ID (currently unused in the smart format). Defaults to 0.

◆ FormatSmartWindows()

void mitk::LogBackendText::FormatSmartWindows ( const LogMessage &  message,
int  threadID 
)
protected

Format a message in smart/short format with colored Windows console output.

Uses Windows Console API to colorize different parts of the log output (timestamp, category, level, message) based on the log level. This method is only available on Windows (compiled when MITK_WIN32_CONSOLE_COLOR is defined).

Parameters
[in]messageThe log message to format and output.
[in]threadIDThread ID (currently unused).

◆ ProcessMessage()

void mitk::LogBackendText::ProcessMessage ( const LogMessage &  message)
overridepure virtual

Process a log message.

Called by the MITK log mechanism for each registered and enabled backend whenever a log message is emitted. Implementations should format and output the message according to their destination.

Parameters
[in]messageThe log message to process. The message text has already been trimmed of trailing whitespace.
Precondition
The backend is registered via RegisterBackend() and its OutputType is enabled.

Implements mitk::LogBackendBase.

Implemented in mitk::LogBackendCout, and mitk::LogBackend.


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