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::ConsoleSinkConfig::Colours &qColors, const quill::ConsoleSinkConfig::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::ConsoleSinkConfig::Colours & |
qColors, |
|
|
const quill::ConsoleSinkConfig::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::ConsoleSinkConfig
-
quill::PatternFormatter
- Author
- Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
- Date
- 2024-08-16
271 :
272 quill::ConsoleSink(
273 [&]
274 {
275
276 quill::ConsoleSinkConfig qConsoleConfig;
277 qConsoleConfig.set_stream(szStream);
278 qConsoleConfig.set_colour_mode(qColorMode);
279 qConsoleConfig.set_colours(qColors);
280 qConsoleConfig.set_override_pattern_formatter_options(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone));
281 return qConsoleConfig;
282 }()),
283 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
284 {}
◆ 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
230 {
231
232 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp,
233 szThreadID,
234 szThreadName,
235 szProcessID,
236 szLoggerName,
237 szLogLevelDescription,
238 szLogLevelShortCode,
239 *qLogMetadata,
240 vNamedArgs,
241 szLogMessage
242 );
243
244
245 if (static_cast<int>(g_eConsoleLogLevel) <= static_cast<int>(qLogLevel))
246 {
247 quill::ConsoleSink::write_log(qLogMetadata,
248 unLogTimestamp,
249 szThreadID,
250 szThreadName,
251 szProcessID,
252 szLoggerName,
253 qLogLevel,
254 szLogLevelDescription,
255 szLogLevelShortCode,
256 vNamedArgs,
257 szLogMessage,
258 szFormattedLogMessage
259 );
260 }
261 }
The documentation for this class was generated from the following files: