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 Namespace Reference

Namespace containing all global type/structs that will be used project wide for logging. More...

Classes

class  LoggingFilter
 This class serves as a container class for handling log filtering of loggers. This must be used if you want each handler to have a different logging level since adding multiple handlers to the same logger will apply the loggers logging level to each handler. More...
 
class  MRDTConsoleSink
 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...
 
class  MRDTRotatingFileSink
 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...
 
class  MRDTRoveCommSink
 A custom logger sink designed to send formatted log messages over the RoveComm protocol. This class extends quill::Sink and is tailored for use in the Autonomy system, where log messages need to be transmitted as packets over a network to a BaseStation via UDP. More...
 

Functions

void InitializeLoggers (std::string szLoggingOutputPath, std::string szProgramTimeLogsDir)
 Logger Initializer - Sets Up all the logging handlers required for having the above loggers.
 

Variables

quill::Logger * g_qFileLogger
 
quill::Logger * g_qConsoleLogger
 
quill::Logger * g_qRoveCommLogger
 
quill::Logger * g_qSharedLogger
 
quill::LogLevel g_eConsoleLogLevel
 
quill::LogLevel g_eFileLogLevel
 
quill::LogLevel g_eRoveCommLogLevel
 
std::string g_szProgramStartTimeString
 
const std::function< void(const rovecomm::RoveCommPacket< uint8_t > &, const sockaddr_in &)> SetLoggingLevelsCallback
 

Detailed Description

Namespace containing all global type/structs that will be used project wide for logging.

Logging Levels:

Author
clayjay3 (clayt.nosp@m.onra.nosp@m.ycowe.nosp@m.n@gm.nosp@m.ail.c.nosp@m.om)
Date
2023-09-30
   Priority > Level     > Description
   Level 1  > TRACE_L3  > Unused
   Level 2  > TRACE_L2  > Unused
   Level 3  > TRACE_L1  > Unused
   Level 4  > DEBUG     > Details that would only be useful in a debug environment
   Level 5  > INFO      > State Changes, RoveComm Updates GPS/IMU/Autonomy, etc
   Level 6  > WARNING   > Something unexpected happened - application could potentially error soon.
   Level 7  > ERROR     > Something went wrong - application could potentially have critical error soon.
   Level 8  > CRITICAL  > Something went very wrong - application will exit after logging is sent.

   Note: At testing sessions we will have "DEBUG" Logging set as the level that is being outputted.
         However, at competition and when using "RELEASE" code we will be using "INFO" Logging. When
         a logging level is set, we only receive logging messages that are that level or higher
         priority.

   Example: When INFO is set, we only receive: INFO, WARNING, ERROR, CRITICAL
            When DEBUG is set, we only receive: DEBUG, INFO, WARNING, ERROR, CRITICAL
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2023-08-22

Function Documentation

◆ InitializeLoggers()

void logging::InitializeLoggers ( std::string  szLoggingOutputPath,
std::string  szProgramTimeLogsDir 
)

Logger Initializer - Sets Up all the logging handlers required for having the above loggers.

Parameters
szLoggingOutputPath- A string containing the filepath to output log files to. Must be properly formatted.
Author
Eli Byrd (edbgk.nosp@m.k@ms.nosp@m.t.edu)
Date
2023-08-22
59 {
60 // Store start time string in member variable.
61 g_szProgramStartTimeString = szProgramTimeLogsDir;
62
63 // Assemble filepath string.
64 std::filesystem::path szFilePath;
65 std::filesystem::path szFilename;
66 szFilePath = szLoggingOutputPath; // Main location for all recordings.
67 szFilePath += g_szProgramStartTimeString + "/"; // Folder for each program run.
68 szFilename = "console_output"; // Base file name.
69
70 // Check if directory exists.
71 if (!std::filesystem::exists(szFilePath))
72 {
73 // Create directory.
74 if (!std::filesystem::create_directories(szFilePath))
75 {
76 // Submit logger message.
77 std::cerr << "Unable to create the logging output directory: " << szFilePath.string() << " for console output file." << std::endl;
78 }
79 }
80 else
81 {
82 // Submit logger message.
83 std::cerr << "Unable to create logging output directory " << szFilePath.string() << ": it already exists." << std::endl;
84 }
85
86 // Construct the full output path.
87 std::filesystem::path szFullOutputPath = szFilePath / szFilename;
88
89 // Set Console Color Profile
90 quill::ConsoleSink::Colours qColors;
91 qColors.apply_default_colours();
92 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL3, constants::szTraceL3Color);
93 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL2, constants::szTraceL2Color);
94 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL1, constants::szTraceL1Color);
95 qColors.assign_colour_to_log_level(quill::LogLevel::Debug, constants::szDebugColor);
96 qColors.assign_colour_to_log_level(quill::LogLevel::Info, constants::szInfoColor);
97 qColors.assign_colour_to_log_level(quill::LogLevel::Warning, constants::szWarningColor);
98 qColors.assign_colour_to_log_level(quill::LogLevel::Error, constants::szErrorColor);
99 qColors.assign_colour_to_log_level(quill::LogLevel::Critical, constants::szCriticalColor);
100 qColors.assign_colour_to_log_level(quill::LogLevel::Backtrace, constants::szBacktraceColor);
101
102 // Create Patterns
103 std::string szLogFilePattern = "%(time) %(log_level) [%(thread_id)] [%(file_name):%(line_number)] %(message)";
104 std::string szCSVFilePattern = "%(time),\t%(log_level),\t[%(thread_id)],\t[%(file_name):%(line_number)],\t\"%(message)\"";
105 std::string szConsolePattern = "%(time) %(log_level:9) [%(thread_id)] [%(file_name):%(line_number)] %(message)";
106 std::string szRoveCommPattern = "%(time) %(log_level) [%(thread_id)] [%(file_name):%(line_number)] %(message)";
107 std::string szTimestampPattern = "%Y-%m-%d %H:%M:%S.%Qms";
108
109 // Create Sinks
110 std::shared_ptr<quill::Sink> qLogFileSink = quill::Frontend::create_or_get_sink<MRDTRotatingFileSink>(
111 szFullOutputPath.replace_extension(".log"), // Log Output Path
112 []()
113 {
114 quill::RotatingFileSinkConfig cfg;
115 cfg.set_open_mode('a');
116 return cfg; // Rotating File Sink Configs
117 }(),
118 szLogFilePattern, // Log Output Pattern
119 szTimestampPattern, // Log Timestamp Pattern
120 quill::Timezone::LocalTime // Log Timezone
121 );
122
123 std::shared_ptr<quill::Sink> qCSVFileSink = quill::Frontend::create_or_get_sink<MRDTRotatingFileSink>(
124 szFullOutputPath.replace_extension(".csv"), // Log Output Path
125 []()
126 {
127 quill::RotatingFileSinkConfig cfg;
128 cfg.set_open_mode('a');
129 return cfg; // Rotating File Sink Configs
130 }(),
131 szCSVFilePattern, // Log Output Pattern
132 szTimestampPattern, // Log Timestamp Pattern
133 quill::Timezone::LocalTime // Log Timezone
134 );
135
136 std::shared_ptr<quill::Sink> qConsoleSink =
137 quill::Frontend::create_or_get_sink<MRDTConsoleSink>("ConsoleSink", // Log Name
138 qColors, // Log Custom Colors
139 quill::ConsoleSink::ColourMode::Automatic, // Detect is console supports colors.
140 szConsolePattern, // Log Output Pattern
141 szTimestampPattern // Log Timestamp Pattern
142 );
143
144 std::shared_ptr<quill::Sink> qMRDTRoveCommSink = quill::Frontend::create_or_get_sink<MRDTRoveCommSink>("MRDTRoveCommSink", // Log Name
145 szRoveCommPattern, // Log Output Pattern
146 szTimestampPattern, // Log Timestamp Pattern
147 quill::Timezone::LocalTime // Log Timezone
148 );
149
150 // Configure Quill
151 quill::BackendOptions qBackendConfig;
152
153 // Start Quill
154 quill::Backend::start(qBackendConfig);
155
156 // Create Loggers
157 g_qFileLogger = quill::Frontend::create_or_get_logger("FILE_LOGGER", {qLogFileSink, qCSVFileSink});
158 g_qConsoleLogger = quill::Frontend::create_or_get_logger("CONSOLE_LOGGER", {qConsoleSink});
159 g_qRoveCommLogger = quill::Frontend::create_or_get_logger("ROVECOMM_LOGGER", {qMRDTRoveCommSink});
160 g_qSharedLogger = quill::Frontend::create_or_get_logger("SHARED_LOGGER", {qLogFileSink, qCSVFileSink, qConsoleSink, qMRDTRoveCommSink});
161
162 // Set Internal Logging Level Limiters
163 g_eFileLogLevel = constants::FILE_DEFAULT_LEVEL;
164 g_eConsoleLogLevel = constants::CONSOLE_DEFAULT_LEVEL;
165 g_eRoveCommLogLevel = constants::ROVECOMM_DEFAULT_LEVEL;
166
167 // Set Base Logging Levels
168 g_qFileLogger->set_log_level(quill::LogLevel::TraceL3);
169 g_qConsoleLogger->set_log_level(quill::LogLevel::TraceL3);
170 g_qSharedLogger->set_log_level(quill::LogLevel::TraceL3);
171 g_qRoveCommLogger->set_log_level(quill::LogLevel::Info);
172
173 // Enable Backtrace
174 g_qFileLogger->init_backtrace(10, quill::LogLevel::Critical);
175 g_qConsoleLogger->init_backtrace(10, quill::LogLevel::Critical);
176 g_qRoveCommLogger->init_backtrace(10, quill::LogLevel::Critical);
177 g_qSharedLogger->init_backtrace(10, quill::LogLevel::Critical);
178 }
Here is the caller graph for this function:

Variable Documentation

◆ SetLoggingLevelsCallback

const std::function<void(const rovecomm::RoveCommPacket<uint8_t>&, const sockaddr_in&)> logging::SetLoggingLevelsCallback
Initial value:
=
[](const rovecomm::RoveCommPacket<uint8_t>& stPacket, const sockaddr_in& stdAddr)
{
(void) stdAddr;
const int nMinConsoleLevel = static_cast<int>(constants::CONSOLE_MIN_LEVEL);
const int nMinFileLevel = static_cast<int>(constants::FILE_MIN_LEVEL);
const int nMinRoveCommLevel = static_cast<int>(constants::ROVECOMM_MIN_LEVEL);
const int nRequestedConsoleLevel = stPacket.vData[0];
const int nRequestedFileLevel = stPacket.vData[1];
const int nRequestedRoveCommLevel = stPacket.vData[2];
bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
bool bRoveCommLevelChangePermitted = nRequestedRoveCommLevel >= nMinRoveCommLevel;
logging::g_eConsoleLogLevel = bConsoleLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[0]) : logging::g_eConsoleLogLevel;
logging::g_eFileLogLevel = bFileLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[1]) : logging::g_eFileLogLevel;
logging::g_eRoveCommLogLevel = bRoveCommLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[2]) : logging::g_eRoveCommLogLevel;
LOG_INFO(logging::g_qSharedLogger, "Incoming SETLOGGINGLEVELS: [Console: {}, File: {}, RoveComm: {}]", stPacket.vData[0], stPacket.vData[1], stPacket.vData[2]);
}
Namespace containing all global type/structs that will be used project wide for logging.
Definition AutonomyLogging.cpp:33
98 {
99 // Not using this.
100 (void) stdAddr;
101
102 // Convert Minimum Permitted Console Level to Integer Value
103 const int nMinConsoleLevel = static_cast<int>(constants::CONSOLE_MIN_LEVEL);
104 const int nMinFileLevel = static_cast<int>(constants::FILE_MIN_LEVEL);
105 const int nMinRoveCommLevel = static_cast<int>(constants::ROVECOMM_MIN_LEVEL);
106
107 // Convert Requested Console Level to Integer Value
108 const int nRequestedConsoleLevel = stPacket.vData[0];
109 const int nRequestedFileLevel = stPacket.vData[1];
110 const int nRequestedRoveCommLevel = stPacket.vData[2];
111
112 // Determine if change is allowed
113 bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
114 bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
115 bool bRoveCommLevelChangePermitted = nRequestedRoveCommLevel >= nMinRoveCommLevel;
116
117 // Convert RoveComm Enumeration to Quill Enumeration and store to logging globals if permitted
118 logging::g_eConsoleLogLevel = bConsoleLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[0]) : logging::g_eConsoleLogLevel;
119 logging::g_eFileLogLevel = bFileLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[1]) : logging::g_eFileLogLevel;
120 logging::g_eRoveCommLogLevel = bRoveCommLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[2]) : logging::g_eRoveCommLogLevel;
121
122 // Submit logger message.
123 LOG_INFO(logging::g_qSharedLogger, "Incoming SETLOGGINGLEVELS: [Console: {}, File: {}, RoveComm: {}]", stPacket.vData[0], stPacket.vData[1], stPacket.vData[2]);
124 };