18#include <quill/Backend.h>
19#include <quill/Frontend.h>
20#include <quill/LogMacros.h>
21#include <quill/Logger.h>
23#include "quill/backend/PatternFormatter.h"
24#include "quill/core/Attributes.h"
25#include "quill/core/Common.h"
26#include "quill/core/Filesystem.h"
28#include "quill/sinks/ConsoleSink.h"
29#include "quill/sinks/RotatingFileSink.h"
31#include <RoveComm/RoveComm.h>
32#include <RoveComm/RoveCommManifest.h>
34#include <shared_mutex>
41#ifndef AUTONOMY_LOGGING_H
42#define AUTONOMY_LOGGING_H
75 extern quill::Logger* g_qFileLogger;
76 extern quill::Logger* g_qConsoleLogger;
77 extern quill::Logger* g_qSharedLogger;
78 extern quill::Logger* g_qRoveCommLogger;
80 extern quill::LogLevel g_eConsoleLogLevel;
81 extern quill::LogLevel g_eFileLogLevel;
82 extern quill::LogLevel g_eRoveCommLogLevel;
84 extern std::string g_szProgramStartTimeString;
85 extern std::string g_szLoggingOutputPath;
97 const std::function<void(
const rovecomm::RoveCommPacket<uint8_t>&,
const sockaddr_in&)> SetLoggingLevelsCallback =
98 [](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
104 const int nMinConsoleLevel =
static_cast<int>(constants::CONSOLE_MIN_LEVEL);
105 const int nMinFileLevel =
static_cast<int>(constants::FILE_MIN_LEVEL);
106 const int nMinRoveCommLevel =
static_cast<int>(constants::ROVECOMM_MIN_LEVEL);
109 const int nRequestedConsoleLevel = stPacket.vData[0];
110 const int nRequestedFileLevel = stPacket.vData[1];
111 const int nRequestedRoveCommLevel = stPacket.vData[2];
114 bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
115 bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
116 bool bRoveCommLevelChangePermitted = nRequestedRoveCommLevel >= nMinRoveCommLevel;
119 logging::g_eConsoleLogLevel = bConsoleLevelChangePermitted ?
static_cast<quill::LogLevel
>(stPacket.vData[0]) :
logging::g_eConsoleLogLevel;
120 logging::g_eFileLogLevel = bFileLevelChangePermitted ?
static_cast<quill::LogLevel
>(stPacket.vData[1]) :
logging::g_eFileLogLevel;
121 logging::g_eRoveCommLogLevel = bRoveCommLevelChangePermitted ?
static_cast<quill::LogLevel
>(stPacket.vData[2]) :
logging::g_eRoveCommLogLevel;
124 LOG_INFO(logging::g_qSharedLogger,
"Incoming SETLOGGINGLEVELS: [Console: {}, File: {}, RoveComm: {}]", stPacket.vData[0], stPacket.vData[1], stPacket.vData[2]);
145 quill::LogLevel m_eMinLogLevel;
157 LoggingFilter(
const std::string szFilterBaseType,
const quill::LogLevel eMinLogLevel) : quill::Filter(szFilterBaseType)
160 m_eMinLogLevel = eMinLogLevel;
182 QUILL_NODISCARD
bool filter(
const quill::MacroMetadata* qLogMetadata,
184 std::string_view szThreadID,
185 std::string_view szThreadName,
186 std::string_view szLoggerName,
187 quill::LogLevel qLogLevel,
188 std::string_view szLogMessage,
189 std::string_view szLogStatement)
noexcept override
193 (void) unLogTimestamp;
198 (void) szLogStatement;
201 return qLogLevel >= m_eMinLogLevel;
266 const quill::ConsoleSinkConfig::ColourMode& qColorMode,
267 const std::string& szFormatPattern,
268 const std::string& szTimeFormat,
269 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
270 const std::string& szStream =
"stdout"
276 quill::ConsoleSinkConfig qConsoleConfig;
277 qConsoleConfig.set_stream(szStream);
278 qConsoleConfig.set_colour_mode(qColorMode);
279 qConsoleConfig.set_colours(qColors);
280 qConsoleConfig.set_override_pattern_formatter_options(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone));
281 return qConsoleConfig;
283 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
286 void write_log(
const quill::MacroMetadata* qLogMetadata,
288 std::string_view szThreadID,
289 std::string_view szThreadName,
290 const std::string& szProcessID,
291 std::string_view szLoggerName,
292 quill::LogLevel qLogLevel,
293 std::string_view szLogLevelDescription,
294 std::string_view szLogLevelShortCode,
295 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
296 std::string_view szLogMessage,
297 std::string_view)
override;
300 quill::PatternFormatter qFormatter;
360 const quill::RotatingFileSinkConfig& qConfig,
361 const std::string& szFormatPattern,
362 const std::string& szTimeFormat,
363 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
364 quill::FileEventNotifier qFileEventNotifier = quill::FileEventNotifier{}
366 quill::RotatingFileSink(qFilename, qConfig, qFileEventNotifier),
367 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
370 void write_log(
const quill::MacroMetadata* qLogMetadata,
372 std::string_view szThreadID,
373 std::string_view szThreadName,
374 const std::string& szProcessID,
375 std::string_view szLoggerName,
376 quill::LogLevel qLogLevel,
377 std::string_view szLogLevelDescription,
378 std::string_view szLogLevelShortCode,
379 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
380 std::string_view szLogMessage,
381 std::string_view)
override;
384 quill::PatternFormatter qFormatter;
417 quill::PatternFormatter qFormatter;
431 std::vector<char> result;
432 int length = std::min(
static_cast<int>(szString.length()), 255);
433 result.reserve(length);
435 for (
int i = 0; i < length; ++i)
437 result.push_back(szString[i]);
467 MRDTRoveCommSink(std::string
const& szFormatPattern, std::string
const& szTimeFormat, quill::Timezone qTimestampTimezone) :
468 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
479 void write_log(
const quill::MacroMetadata* qLogMetadata,
481 std::string_view szThreadID,
482 std::string_view szThreadName,
483 const std::string& szProcessID,
484 std::string_view szLoggerName,
485 quill::LogLevel qLogLevel,
486 std::string_view szLogLevelDescription,
487 std::string_view szLogLevelShortCode,
488 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
489 std::string_view szLogMessage,
490 std::string_view)
override;
Declares constants for the autonomy software.
Defines and implements functions related to operations on time and date within the timeops namespace.
This class serves as a container class for handling log filtering of loggers. This must be used if yo...
Definition AutonomyLogging.h:142
QUILL_NODISCARD bool filter(const quill::MacroMetadata *qLogMetadata, uint64_t unLogTimestamp, std::string_view szThreadID, std::string_view szThreadName, std::string_view szLoggerName, quill::LogLevel qLogLevel, std::string_view szLogMessage, std::string_view szLogStatement) noexcept override
This method should never be called by this codebase, it is called internally by the quill library....
Definition AutonomyLogging.h:182
LoggingFilter(const std::string szFilterBaseType, const quill::LogLevel eMinLogLevel)
Construct a new Console Filter object.
Definition AutonomyLogging.h:157
A custom console sink for logging messages with specific formatting and timestamping....
Definition AutonomyLogging.h:238
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....
Definition AutonomyLogging.h:265
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,...
Definition AutonomyLogging.cpp:219
A custom rotating file sink that formats and logs messages to a file with automatic rotation based on...
Definition AutonomyLogging.h:332
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 custo...
Definition AutonomyLogging.cpp:301
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,...
Definition AutonomyLogging.h:359
A custom logger sink designed to send formatted log messages over the RoveComm protocol....
Definition AutonomyLogging.h:415
MRDTRoveCommSink(std::string const &szFormatPattern, std::string const &szTimeFormat, quill::Timezone qTimestampTimezone)
Constructs a new MRDTRoveCommSink object with the specified format pattern, time format,...
Definition AutonomyLogging.h:467
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
Formats a log message and sends it as a RoveComm packet to the BaseStation. The log message is format...
Definition AutonomyLogging.cpp:390
~MRDTRoveCommSink() override=default
Destroy the MRDTRoveCommSink object.
std::vector< char > StringToVector(const std::string &szString)
A utility function to convert a string to a vector that is no longer than 255 characters long.
Definition AutonomyLogging.h:429
void flush_sink() noexcept override
This method should never be called by this codebase, it is called internally by the quill library.
Definition AutonomyLogging.h:499
Namespace containing all global type/structs that will be used project wide for logging.
Definition AutonomyLogging.cpp:34
void InitializeLoggers(std::string szLoggingOutputPath, std::string szProgramTimeLogsDir)
Logger Initializer - Sets Up all the logging handlers required for having the above loggers.
Definition AutonomyLogging.cpp:60
std::string GetTimestamp(const std::string &szFormat="%Y%m%d-%H%M%S")
Accessor for getting the current time in a specified format.
Definition TimeOperations.hpp:42