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;
79 extern quill::LogLevel g_eConsoleLogLevel;
80 extern quill::LogLevel g_eFileLogLevel;
82 extern std::string g_szProgramStartTimeString;
83 extern std::string g_szLoggingOutputPath;
95 const std::function<void(
const rovecomm::RoveCommPacket<uint8_t>&,
const sockaddr_in&)> SetLoggingLevelsCallback =
96 [](
const rovecomm::RoveCommPacket<uint8_t>& stPacket,
const sockaddr_in& stdAddr)
102 const int nMinConsoleLevel =
static_cast<int>(constants::CONSOLE_MIN_LEVEL);
103 const int nMinFileLevel =
static_cast<int>(constants::FILE_MIN_LEVEL);
106 const int nRequestedConsoleLevel = stPacket.vData[0];
107 const int nRequestedFileLevel = stPacket.vData[1];
110 bool bConsoleLevelChangePermitted = nRequestedConsoleLevel >= nMinConsoleLevel;
111 bool bFileLevelChangePermitted = nRequestedFileLevel >= nMinFileLevel;
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;
118 LOG_INFO(logging::g_qSharedLogger,
"Incoming SETLOGGINGLEVELS: [Console: {}, File: {}]", stPacket.vData[0], stPacket.vData[1]);
139 quill::LogLevel m_eMinLogLevel;
151 LoggingFilter(
const std::string szFilterBaseType,
const quill::LogLevel eMinLogLevel) : quill::Filter(szFilterBaseType)
154 m_eMinLogLevel = eMinLogLevel;
176 QUILL_NODISCARD
bool filter(
const quill::MacroMetadata* qLogMetadata,
178 std::string_view szThreadID,
179 std::string_view szThreadName,
180 std::string_view szLoggerName,
181 quill::LogLevel qLogLevel,
182 std::string_view szLogMessage,
183 std::string_view szLogStatement)
noexcept override
187 (void) unLogTimestamp;
192 (void) szLogStatement;
195 return qLogLevel >= m_eMinLogLevel;
260 const quill::ConsoleSinkConfig::ColourMode& qColorMode,
261 const std::string& szFormatPattern,
262 const std::string& szTimeFormat,
263 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
264 const std::string& szStream =
"stdout"
270 quill::ConsoleSinkConfig qConsoleConfig;
271 qConsoleConfig.set_stream(szStream);
272 qConsoleConfig.set_colour_mode(qColorMode);
273 qConsoleConfig.set_colours(qColors);
274 qConsoleConfig.set_override_pattern_formatter_options(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone));
275 return qConsoleConfig;
277 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
280 void write_log(
const quill::MacroMetadata* qLogMetadata,
282 std::string_view szThreadID,
283 std::string_view szThreadName,
284 const std::string& szProcessID,
285 std::string_view szLoggerName,
286 quill::LogLevel qLogLevel,
287 std::string_view szLogLevelDescription,
288 std::string_view szLogLevelShortCode,
289 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
290 std::string_view szLogMessage,
291 std::string_view)
override;
294 quill::PatternFormatter qFormatter;
354 const quill::RotatingFileSinkConfig& qConfig,
355 const std::string& szFormatPattern,
356 const std::string& szTimeFormat,
357 quill::Timezone qTimestampTimezone = quill::Timezone::LocalTime,
358 quill::FileEventNotifier qFileEventNotifier = quill::FileEventNotifier{}
360 quill::RotatingFileSink(qFilename, qConfig, qFileEventNotifier),
361 qFormatter(quill::PatternFormatterOptions(szFormatPattern, szTimeFormat, qTimestampTimezone))
364 void write_log(
const quill::MacroMetadata* qLogMetadata,
366 std::string_view szThreadID,
367 std::string_view szThreadName,
368 const std::string& szProcessID,
369 std::string_view szLoggerName,
370 quill::LogLevel qLogLevel,
371 std::string_view szLogLevelDescription,
372 std::string_view szLogLevelShortCode,
373 const std::vector<std::pair<std::string, std::string>>* vNamedArgs,
374 std::string_view szLogMessage,
375 std::string_view)
override;
378 quill::PatternFormatter qFormatter;
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:136
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:176
LoggingFilter(const std::string szFilterBaseType, const quill::LogLevel eMinLogLevel)
Construct a new Console Filter object.
Definition AutonomyLogging.h:151
A custom console sink for logging messages with specific formatting and timestamping....
Definition AutonomyLogging.h:232
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:259
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:205
A custom rotating file sink that formats and logs messages to a file with automatic rotation based on...
Definition AutonomyLogging.h:326
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:287
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:353
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:57
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