A custom console sink for logging messages with specific formatting and timestamping. This class extends quill::ConsoleSink
and provides the capability to format log messages using a specified pattern and time format, allowing for customizable and colorized console outputs.
More...
#include <AutonomyLogging.h>
|
| MRDTConsoleSink (const quill::ConsoleSink::Colours &qColors, const quill::ConsoleSink::ColourMode &qColorMode, const std::string &szFormatPattern, const std::string &szTimeFormat, quill::Timezone qTimestampTimezone=quill::Timezone::LocalTime, const std::string &szStream="stdout") |
| Constructs a new MRDTConsoleSink object with specified formatting and console colors. This constructor initializes the sink with a log message pattern, timestamp format, and optional timezone settings. The constructor also allows customization of the output szStream.
|
|
void | write_log (const quill::MacroMetadata *qLogMetadata, uint64_t unLogTimestamp, std::string_view szThreadID, std::string_view szThreadName, const std::string &szProcessID, std::string_view szLoggerName, quill::LogLevel qLogLevel, std::string_view szLogLevelDescription, std::string_view szLogLevelShortCode, const std::vector< std::pair< std::string, std::string > > *vNamedArgs, std::string_view szLogMessage, std::string_view) override |
| Writes a log message to the MRDT console sink, formats the message using the provided formatter, and then passes the formatted log message along with the original data to the parent class (ConsoleSink) for handling.
|
|
|
quill::PatternFormatter | qFormatter |
|
A custom console sink for logging messages with specific formatting and timestamping. This class extends quill::ConsoleSink
and provides the capability to format log messages using a specified pattern and time format, allowing for customizable and colorized console outputs.
This class is intended to be used in scenarios where real-time logging to the console is required, such as during development, testing, and production. It supports different formatting options, including log level descriptions, thread information, timestamps, and log messages.
Key Features:
- Customizable log message formats using a pattern.
- Colorized console output to highlight log levels.
- Supports different timestamp formats and timezones.
- Inherits from
quill::ConsoleSink
for seamless integration with Quill's logging framework.
- Note
- This class should be used for logging real-time information to the console. It is flexible enough to handle different environments, including testing and production, by adjusting the formatting and log levels.
- See also
- quill::ConsoleSink
-
quill::PatternFormatter
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
◆ MRDTConsoleSink()
logging::MRDTConsoleSink::MRDTConsoleSink |
( |
const quill::ConsoleSink::Colours & |
qColors, |
|
|
const quill::ConsoleSink::ColourMode & |
qColorMode, |
|
|
const std::string & |
szFormatPattern, |
|
|
const std::string & |
szTimeFormat, |
|
|
quill::Timezone |
qTimestampTimezone = quill::Timezone::LocalTime , |
|
|
const std::string & |
szStream = "stdout" |
|
) |
| |
|
inline |
Constructs a new MRDTConsoleSink object with specified formatting and console colors. This constructor initializes the sink with a log message pattern, timestamp format, and optional timezone settings. The constructor also allows customization of the output szStream.
- Parameters
-
qColors | - The console colors configuration for highlighting log levels. |
szFormatPattern | - The pattern used to format the log message. |
szTimeFormat | - The format of the timestamp in the log message. |
qTimestampTimezone | - The timezone used for the timestamp (default: LocalTime). |
szStream | - The szStream to output the logs to (default: "stdout"). |
- Note
- Ensure that the format pattern and time format are properly defined before using this constructor, as they directly affect the log output structure.
- Warning
- Incorrect configuration of format patterns or time formats may lead to malformed log outputs.
- See also
- quill::ConsoleSink
-
quill::PatternFormatter
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
269 :
270 quill::ConsoleSink(qColors, qColorMode, szStream),
271 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
272 {}
◆ write_log()
void logging::MRDTConsoleSink::write_log |
( |
const quill::MacroMetadata * |
qLogMetadata, |
|
|
uint64_t |
unLogTimestamp, |
|
|
std::string_view |
szThreadID, |
|
|
std::string_view |
szThreadName, |
|
|
const std::string & |
szProcessID, |
|
|
std::string_view |
szLoggerName, |
|
|
quill::LogLevel |
qLogLevel, |
|
|
std::string_view |
szLogLevelDescription, |
|
|
std::string_view |
szLogLevelShortCode, |
|
|
const std::vector< std::pair< std::string, std::string > > * |
vNamedArgs, |
|
|
std::string_view |
szLogMessage, |
|
|
std::string_view |
|
|
) |
| |
|
override |
Writes a log message to the MRDT console sink, formats the message using the provided formatter, and then passes the formatted log message along with the original data to the parent class (ConsoleSink) for handling.
- Parameters
-
qLogMetadata | - Metadata about the log statement (e.g., file, line number). |
unLogTimestamp | - The timestamp of the log statement. |
szThreadID | - The ID of the thread that generated the log. |
szThreadName | - The name of the thread that generated the log. |
szProcessID | - The ID of the process that generated the log. |
szLoggerName | - The name of the logger that generated the log. |
qLogLevel | - The level/severity of the log statement. |
szLogLevelDescription | - A description of the log level. |
szLogLevelShortCode | - A short code representing the log level. |
vNamedArgs | - Optional named arguments passed with the log statement. |
szLogMessage | - The actual log message content. |
- Note
- This method calls the base class's
write_log
function to actually handle the log output, after formatting the message with custom formatting logic.
-
This method should not be called directly. It is meant to be invoked by the logging framework as part of the log handling process.
- See also
- quill::ConsoleSink
- Warning
- Ensure that the formatter is correctly configured before using this method, as improper formatting may lead to incorrect log outputs.
- Attention
- This method overrides the base class's write_log function to inject custom formatting logic while preserving the core file logging functionality.
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
226 {
227
228 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp,
229 szThreadID,
230 szThreadName,
231 szProcessID,
232 szLoggerName,
233 szLogLevelDescription,
234 szLogLevelShortCode,
235 *qLogMetadata,
236 vNamedArgs,
237 szLogMessage
238 );
239
240
241 if (static_cast<int>(g_eConsoleLogLevel) <= static_cast<int>(qLogLevel))
242 {
243 quill::ConsoleSink::write_log(qLogMetadata,
244 unLogTimestamp,
245 szThreadID,
246 szThreadName,
247 szProcessID,
248 szLoggerName,
249 qLogLevel,
250 szLogLevelDescription,
251 szLogLevelShortCode,
252 vNamedArgs,
253 szLogMessage,
254 szFormattedLogMessage
255 );
256 }
257 }
The documentation for this class was generated from the following files: