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>
38#include "./AutonomyConstants.h"
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;
96 const std::function<void(
const rovecomm::RoveCommPacket<uint8_t>&,
const sockaddr_in&)> SetLoggingLevelsCallback =
97 [](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
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);
108 const int nRequestedConsoleLevel = stPacket.vData[0];
109 const int nRequestedFileLevel = stPacket.vData[1];
110 const int nRequestedRoveCommLevel = stPacket.vData[2];
113 bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
114 bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
115 bool bRoveCommLevelChangePermitted = nRequestedRoveCommLevel >= nMinRoveCommLevel;
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;
123 LOG_INFO(logging::g_qSharedLogger,
"Incoming SETLOGGINGLEVELS: [Console: {}, File: {}, RoveComm: {}]", stPacket.vData[0], stPacket.vData[1], stPacket.vData[2]);
144 quill::LogLevel m_eMinLogLevel;
156 LoggingFilter(
const std::string szFilterBaseType,
const quill::LogLevel eMinLogLevel) : quill::Filter(szFilterBaseType)
159 m_eMinLogLevel = eMinLogLevel;
181 QUILL_NODISCARD
bool filter(
const quill::MacroMetadata* qLogMetadata,
183 std::string_view szThreadID,
184 std::string_view szThreadName,
185 std::string_view szLoggerName,
186 quill::LogLevel qLogLevel,
187 std::string_view szLogMessage,
188 std::string_view szLogStatement)
noexcept override
192 (void) unLogTimestamp;
197 (void) szLogStatement;
200 return qLogLevel >= m_eMinLogLevel;
264 const quill::ConsoleSink::ColourMode& qColorMode,
265 const std::string& szFormatPattern,
266 const std::string& szTimeFormat,
267 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
268 const std::string& szStream =
"stdout"
270 quill::ConsoleSink(qColors, qColorMode, szStream),
271 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
274 void write_log(
const quill::MacroMetadata* qLogMetadata,
276 std::string_view szThreadID,
277 std::string_view szThreadName,
278 const std::string& szProcessID,
279 std::string_view szLoggerName,
280 quill::LogLevel qLogLevel,
281 std::string_view szLogLevelDescription,
282 std::string_view szLogLevelShortCode,
283 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
284 std::string_view szLogMessage,
285 std::string_view)
override;
288 quill::PatternFormatter qFormatter;
348 const quill::RotatingFileSinkConfig& qConfig,
349 const std::string& szFormatPattern,
350 const std::string& szTimeFormat,
351 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
352 quill::FileEventNotifier qFileEventNotifier = quill::FileEventNotifier{}
354 quill::RotatingFileSink(qFilename, qConfig, qFileEventNotifier),
355 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
358 void write_log(
const quill::MacroMetadata* qLogMetadata,
360 std::string_view szThreadID,
361 std::string_view szThreadName,
362 const std::string& szProcessID,
363 std::string_view szLoggerName,
364 quill::LogLevel qLogLevel,
365 std::string_view szLogLevelDescription,
366 std::string_view szLogLevelShortCode,
367 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
368 std::string_view szLogMessage,
369 std::string_view)
override;
372 quill::PatternFormatter qFormatter;
405 quill::PatternFormatter qFormatter;
419 std::vector<char> result;
420 int length = std::min(
static_cast<int>(szString.length()), 255);
421 result.reserve(length);
423 for (
int i = 0; i < length; ++i)
425 result.push_back(szString[i]);
455 MRDTRoveCommSink(std::string
const& szFormatPattern, std::string
const& szTimeFormat, quill::Timezone qTimestampTimezone) :
456 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
467 void write_log(
const quill::MacroMetadata* qLogMetadata,
469 std::string_view szThreadID,
470 std::string_view szThreadName,
471 const std::string& szProcessID,
472 std::string_view szLoggerName,
473 quill::LogLevel qLogLevel,
474 std::string_view szLogLevelDescription,
475 std::string_view szLogLevelShortCode,
476 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
477 std::string_view szLogMessage,
478 std::string_view)
override;
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:141
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:181
LoggingFilter(const std::string szFilterBaseType, const quill::LogLevel eMinLogLevel)
Construct a new Console Filter object.
Definition AutonomyLogging.h:156
A custom console sink for logging messages with specific formatting and timestamping....
Definition AutonomyLogging.h:237
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:214
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....
Definition AutonomyLogging.h:263
A custom rotating file sink that formats and logs messages to a file with automatic rotation based on...
Definition AutonomyLogging.h:320
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:296
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:347
A custom logger sink designed to send formatted log messages over the RoveComm protocol....
Definition AutonomyLogging.h:403
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:455
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:385
~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:417
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:487
Namespace containing all global type/structs that will be used project wide for logging.
Definition AutonomyLogging.cpp:33
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:58
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