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::MRDTRotatingFileSink Class Reference

A custom rotating file sink that formats and logs messages to a file with automatic rotation based on file size or time interval. This class extends quill::RotatingFileSink and provides the ability to format log messages using a pattern and time format, ensuring that logs are written to a rotating file system. More...

#include <AutonomyLogging.h>

Inheritance diagram for logging::MRDTRotatingFileSink:
Collaboration diagram for logging::MRDTRotatingFileSink:

Public Member Functions

 MRDTRotatingFileSink (const quill::fs::path &qFilename, const quill::RotatingFileSinkConfig &qConfig, const std::string &szFormatPattern, const std::string &szTimeFormat, quill::Timezone qTimestampTimezone=quill::Timezone::LocalTime, quill::FileEventNotifier qFileEventNotifier=quill::FileEventNotifier{})
 Constructs a new MRDTRotatingFileSink object with specified formatting, file rotation settings, and an optional file event notifier. This constructor initializes the sink with a log message pattern, timestamp format, and configuration for rotating the log file based on size or time interval.
 
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 rotating file sink. The log message is first formatted using a custom formatter, and then the formatted message along with the original log details are passed to the base class (RotatingFileSink) for further handling (such as writing to a rotating log file).
 

Private Attributes

quill::PatternFormatter qFormatter
 

Detailed Description

A custom rotating file sink that formats and logs messages to a file with automatic rotation based on file size or time interval. This class extends quill::RotatingFileSink and provides the ability to format log messages using a pattern and time format, ensuring that logs are written to a rotating file system.

This class is ideal for scenarios where log files need to be managed based on size or time constraints, such as in long-running applications. It formats the log messages before writing them to files, making it easy to store logs with consistent formatting while preventing file bloat through rotation.

Key Features:

  • Customizable log message formats using a pattern.
  • Automatic file rotation based on configurable size or time intervals.
  • Supports different timestamp formats and timezones for log entries.
  • Inherits from quill::RotatingFileSink for easy integration with Quill's logging framework.
Note
This class is designed to handle file-based logging with automatic rotation, making it suitable for use in both development and production environments.
See also
quill::RotatingFileSink
quill::PatternFormatter
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-08-16

Constructor & Destructor Documentation

◆ MRDTRotatingFileSink()

logging::MRDTRotatingFileSink::MRDTRotatingFileSink ( const quill::fs::path &  qFilename,
const quill::RotatingFileSinkConfig &  qConfig,
const std::string &  szFormatPattern,
const std::string &  szTimeFormat,
quill::Timezone  qTimestampTimezone = quill::Timezone::LocalTime,
quill::FileEventNotifier  qFileEventNotifier = quill::FileEventNotifier{} 
)
inline

Constructs a new MRDTRotatingFileSink object with specified formatting, file rotation settings, and an optional file event notifier. This constructor initializes the sink with a log message pattern, timestamp format, and configuration for rotating the log file based on size or time interval.

Parameters
qFilename- The path to the log file.
qConfig- The configuration for rotating the log file (e.g., based on size or time).
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).
qFileEventNotifier- Optional event notifier for file-related events (default: none).
Note
Ensure that the file rotation configuration (config) is correctly set up to avoid unexpected log file behavior. The format pattern and time format should also be defined correctly to ensure logs are written with the intended structure.
Warning
Misconfiguration of file rotation settings or format patterns may result in loss of log data or malformed log outputs.
See also
quill::RotatingFileSink
quill::PatternFormatter
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2024-08-16
352 {} // Event Notifier (Default: None)
353 ) :
354 quill::RotatingFileSink(qFilename, qConfig, qFileEventNotifier), // Pass Parameters into quill::RotatingFileSink
355 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone)) // Pass Parameters into qFormatter type
356 {}

Member Function Documentation

◆ write_log()

void logging::MRDTRotatingFileSink::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 rotating file sink. The log message is first formatted using a custom formatter, and then the formatted message along with the original log details are passed to the base class (RotatingFileSink) for further handling (such as writing to a rotating log file).

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 formats the log message using the provided formatter, ensuring that the final output adheres to the defined format pattern. The formatted message is then handled by the rotating file sink for writing to a file that rotates based on file size or time interval.
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::RotatingFileSink
Warning
Ensure that the formatter is correctly configured and that the rotating file sink is properly set up to avoid loss of log data.
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
308 {
309 // Format the log message
310 std::string_view szFormattedLogMessage = qFormatter.format(unLogTimestamp, // Timestamp
311 szThreadID, // Thread ID
312 szThreadName, // Thread name
313 szProcessID, // Process ID
314 szLoggerName, // Logger name
315 szLogLevelDescription, // Log level description
316 szLogLevelShortCode, // Log level short code
317 *qLogMetadata, // Log statement metadata
318 vNamedArgs, // Named arguments
319 szLogMessage // Log message
320 );
321
322 // Check if logging level is permitted
323 if (static_cast<int>(g_eFileLogLevel) <= static_cast<int>(qLogLevel))
324 {
325 quill::RotatingFileSink::write_log(qLogMetadata, // Metadata
326 unLogTimestamp, // Timestamp
327 szThreadID, // Thread ID
328 szThreadName, // Thread Name
329 szProcessID, // Process ID
330 szLoggerName, // Logger name
331 qLogLevel, // Log level
332 szLogLevelDescription, // Log level description
333 szLogLevelShortCode, // Log level short code
334 vNamedArgs, // Named arguments
335 szLogMessage, // Log Message
336 szFormattedLogMessage // Formatted Log Message
337 );
338 }
339 }

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