Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
logging::MRDTConsoleSink Class Reference

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>

Inheritance diagram for logging::MRDTConsoleSink:
Collaboration diagram for logging::MRDTConsoleSink:

Public Member Functions

 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.
 

Private Attributes

quill::PatternFormatter qFormatter
 

Detailed Description

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

Constructor & Destructor Documentation

◆ 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), // Pass Parameters into quill::ConsoleSink
271 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone)) // Pass Parameters into qFormatter type
272 {}

Member Function Documentation

◆ 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 // Format the log message
228 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp, // Timestamp
229 szThreadID, // Thread ID
230 szThreadName, // Thread name
231 szProcessID, // Process ID
232 szLoggerName, // Logger name
233 szLogLevelDescription, // Log level description
234 szLogLevelShortCode, // Log level short code
235 *qLogMetadata, // Log statement metadata
236 vNamedArgs, // Named arguments
237 szLogMessage // Log message
238 );
239
240 // Check if logging level is permitted
241 if (static_cast<int>(g_eConsoleLogLevel) <= static_cast<int>(qLogLevel))
242 {
243 quill::ConsoleSink::write_log(qLogMetadata, // Metadata
244 unLogTimestamp, // Timestamp
245 szThreadID, // Thread ID
246 szThreadName, // Thread Name
247 szProcessID, // Process ID
248 szLoggerName, // Logger name
249 qLogLevel, // Log level
250 szLogLevelDescription, // Log level description
251 szLogLevelShortCode, // Log level short code
252 vNamedArgs, // Named arguments
253 szLogMessage, // Log Message
254 szFormattedLogMessage // Formatted Log Message
255 );
256 }
257 }

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