Abstract superclass for text-based log backends.
More...
#include <mitkLogBackendText.h>
|
| 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...
|
| |
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.
◆ ~LogBackendText()
| mitk::LogBackendText::~LogBackendText |
( |
| ) |
|
|
override |
◆ 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] | out | The 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] | message | The log message to format and output. |
| [in] | threadID | Optional 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] | out | The output stream to write the formatted message to. |
| [in] | message | The log message to format. |
| [in] | threadID | Optional 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] | message | The log message to format and output. |
| [in] | threadID | Optional 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] | out | The output stream to write the formatted message to. |
| [in] | message | The log message to format. |
| [in] | threadID | Optional 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] | message | The log message to format and output. |
| [in] | threadID | Thread 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] | message | The 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: