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...
 

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_qSharedLogger
 
quill::LogLevel g_eConsoleLogLevel
 
quill::LogLevel g_eFileLogLevel
 
std::string g_szProgramStartTimeString
 
std::string g_szLoggingOutputPath
 
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
58 {
59 // Store start time string in member variable.
60 g_szProgramStartTimeString = szProgramTimeLogsDir;
61
62 // Assemble filepath string.
63 std::filesystem::path szFilePath;
64 std::filesystem::path szFilename;
65 szFilePath = szLoggingOutputPath; // Main location for all recordings.
66 szFilePath += g_szProgramStartTimeString + "/"; // Folder for each program run.
67 szFilename = "console_output"; // Base file name.
68
69 // Store the logging output path.
70 g_szLoggingOutputPath = szFilePath;
71
72 // Check if directory exists.
73 if (!std::filesystem::exists(szFilePath))
74 {
75 // Create directory.
76 if (!std::filesystem::create_directories(szFilePath))
77 {
78 // Submit logger message.
79 std::cerr << "Unable to create the logging output directory: " << szFilePath.string() << " for console output file." << std::endl;
80 }
81 }
82 else
83 {
84 // Submit logger message.
85 std::cerr << "Unable to create logging output directory " << szFilePath.string() << ": it already exists." << std::endl;
86 }
87
88 // Construct the full output path.
89 std::filesystem::path szFullOutputPath = szFilePath / szFilename;
90
91 // Set Console Color Profile
92 quill::ConsoleSinkConfig::Colours qColors;
93 qColors.apply_default_colours();
94 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL3, constants::szTraceL3Color);
95 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL2, constants::szTraceL2Color);
96 qColors.assign_colour_to_log_level(quill::LogLevel::TraceL1, constants::szTraceL1Color);
97 qColors.assign_colour_to_log_level(quill::LogLevel::Debug, constants::szDebugColor);
98 qColors.assign_colour_to_log_level(quill::LogLevel::Info, constants::szInfoColor);
99 qColors.assign_colour_to_log_level(quill::LogLevel::Warning, constants::szWarningColor);
100 qColors.assign_colour_to_log_level(quill::LogLevel::Error, constants::szErrorColor);
101 qColors.assign_colour_to_log_level(quill::LogLevel::Critical, constants::szCriticalColor);
102 qColors.assign_colour_to_log_level(quill::LogLevel::Backtrace, constants::szBacktraceColor);
103
104 // Create Patterns
105 std::string szLogFilePattern = "%(time) %(log_level) [%(thread_id)] [%(file_name):%(line_number)] %(message)";
106 std::string szCSVFilePattern = "%(time),\t%(log_level),\t[%(thread_id)],\t[%(file_name):%(line_number)],\t\"%(message)\"";
107 std::string szConsolePattern = "%(time) %(log_level:9) [%(thread_id)] [%(file_name):%(line_number)] %(message)";
108 std::string szTimestampPattern = "%Y-%m-%d %H:%M:%S.%Qms";
109
110 // Create Sinks
111 std::shared_ptr<quill::Sink> qLogFileSink = quill::Frontend::create_or_get_sink<MRDTRotatingFileSink>(
112 szFullOutputPath.replace_extension(".log"), // Log Output Path
113 []()
114 {
115 quill::RotatingFileSinkConfig cfg;
116 cfg.set_open_mode('a');
117 return cfg; // Rotating File Sink Configs
118 }(),
119 szLogFilePattern, // Log Output Pattern
120 szTimestampPattern, // Log Timestamp Pattern
121 quill::Timezone::LocalTime // Log Timezone
122 );
123
124 std::shared_ptr<quill::Sink> qCSVFileSink = quill::Frontend::create_or_get_sink<MRDTRotatingFileSink>(
125 szFullOutputPath.replace_extension(".csv"), // Log Output Path
126 []()
127 {
128 quill::RotatingFileSinkConfig cfg;
129 cfg.set_open_mode('a');
130 return cfg; // Rotating File Sink Configs
131 }(),
132 szCSVFilePattern, // Log Output Pattern
133 szTimestampPattern, // Log Timestamp Pattern
134 quill::Timezone::LocalTime // Log Timezone
135 );
136
137 std::shared_ptr<quill::Sink> qConsoleSink =
138 quill::Frontend::create_or_get_sink<MRDTConsoleSink>("ConsoleSink", // Log Name
139 qColors, // Log Custom Colors
140 quill::ConsoleSinkConfig::ColourMode::Automatic, // Detect is console supports colors.
141 szConsolePattern, // Log Output Pattern
142 szTimestampPattern // Log Timestamp Pattern
143 );
144
145 // Configure Quill
146 quill::BackendOptions qBackendConfig;
147
148 // Start Quill
149 quill::Backend::start(qBackendConfig);
150
151 // Create Loggers
152 g_qFileLogger = quill::Frontend::create_or_get_logger("FILE_LOGGER", {qLogFileSink, qCSVFileSink});
153 g_qConsoleLogger = quill::Frontend::create_or_get_logger("CONSOLE_LOGGER", {qConsoleSink});
154 g_qSharedLogger = quill::Frontend::create_or_get_logger("SHARED_LOGGER", {qLogFileSink, qCSVFileSink, qConsoleSink});
155
156 // Set Internal Logging Level Limiters
157 g_eFileLogLevel = constants::FILE_DEFAULT_LEVEL;
158 g_eConsoleLogLevel = constants::CONSOLE_DEFAULT_LEVEL;
159
160 // Set Base Logging Levels
161 g_qFileLogger->set_log_level(quill::LogLevel::TraceL3);
162 g_qConsoleLogger->set_log_level(quill::LogLevel::TraceL3);
163 g_qSharedLogger->set_log_level(quill::LogLevel::TraceL3);
164
165 // Enable Backtrace
166 g_qFileLogger->init_backtrace(10, quill::LogLevel::Critical);
167 g_qConsoleLogger->init_backtrace(10, quill::LogLevel::Critical);
168 g_qSharedLogger->init_backtrace(10, quill::LogLevel::Critical);
169 }
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 nRequestedConsoleLevel = stPacket.vData[0];
const int nRequestedFileLevel = stPacket.vData[1];
bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
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;
LOG_INFO(logging::g_qSharedLogger, "Incoming SETLOGGINGLEVELS: [Console: {}, File: {}]", stPacket.vData[0], stPacket.vData[1]);
}
Namespace containing all global type/structs that will be used project wide for logging.
Definition AutonomyLogging.cpp:33
97 {
98 // Not using this.
99 (void) stdAddr;
100
101 // Convert Minimum Permitted Console Level to Integer Value
102 const int nMinConsoleLevel = static_cast<int>(constants::CONSOLE_MIN_LEVEL);
103 const int nMinFileLevel = static_cast<int>(constants::FILE_MIN_LEVEL);
104
105 // Convert Requested Console Level to Integer Value
106 const int nRequestedConsoleLevel = stPacket.vData[0];
107 const int nRequestedFileLevel = stPacket.vData[1];
108
109 // Determine if change is allowed
110 bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
111 bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
112
113 // Convert RoveComm Enumeration to Quill Enumeration and store to logging globals if permitted
114 logging::g_eConsoleLogLevel = bConsoleLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[0]) : logging::g_eConsoleLogLevel;
115 logging::g_eFileLogLevel = bFileLevelChangePermitted ? static_cast<quill::LogLevel>(stPacket.vData[1]) : logging::g_eFileLogLevel;
116
117 // Submit logger message.
118 LOG_INFO(logging::g_qSharedLogger, "Incoming SETLOGGINGLEVELS: [Console: {}, File: {}]", stPacket.vData[0], stPacket.vData[1]);
119 };