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
265 :
266 quill::ConsoleSink(
267 [&]
268 {
269
270 quill::ConsoleSinkConfig qConsoleConfig;
271 qConsoleConfig.set_stream(szStream);
272 qConsoleConfig.set_colour_mode(qColorMode);
273 qConsoleConfig.set_colours(qColors);
274 qConsoleConfig.set_override_pattern_formatter_options(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone));
275 return qConsoleConfig;
276 }()),
277 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
278 {}
◆ 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
217 {
218
219 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp,
220 szThreadID,
221 szThreadName,
222 szProcessID,
223 szLoggerName,
224 szLogLevelDescription,
225 szLogLevelShortCode,
226 *qLogMetadata,
227 vNamedArgs,
228 szLogMessage
229 );
230
231
232 if (static_cast<int>(g_eConsoleLogLevel) <= static_cast<int>(qLogLevel))
233 {
234 quill::ConsoleSink::write_log(qLogMetadata,
235 unLogTimestamp,
236 szThreadID,
237 szThreadName,
238 szProcessID,
239 szLoggerName,
240 qLogLevel,
241 szLogLevelDescription,
242 szLogLevelShortCode,
243 vNamedArgs,
244 szLogMessage,
245 szFormattedLogMessage
246 );
247 }
248 }
The documentation for this class was generated from the following files: