diff --git a/inc/Logger.hpp b/inc/Logger.hpp index f4b6bdd85bee0f8c5c54a1bc55d3fd398f315599..ec0e41428b42a2bfee5e85f8a234ace1ad6a189d 100644 --- a/inc/Logger.hpp +++ b/inc/Logger.hpp @@ -4,7 +4,7 @@ #include <cstdint> #include <etl/String.hpp> #include <etl/to_string.h> -#include <ECSS_Definitions.hpp> +#include "ECSS_Definitions.hpp" #if defined LOGLEVEL_TRACE #define LOGLEVEL Logger::trace // Ignore-MISRA @@ -20,7 +20,7 @@ #define LOGLEVEL Logger::error // Ignore-MISRA #elif defined LOGLEVEL_EMERGENCY #define LOGLEVEL Logger::emergency // Ignore-MISRA -#else +#elif !defined LOGLEVEL #define LOGLEVEL Logger::disabled // Ignore-MISRA #endif @@ -51,6 +51,11 @@ public: */ typedef uint8_t LogLevelType; + /** + * ETL's string format specification, to be used for all logged messages + */ + static etl::format_spec format; + /** * Log levels supported by the logger. Each level represents a different severity of the logged Message, * and messages of lower severities can be filtered on top of more significant ones. @@ -58,7 +63,6 @@ public: * Each severity is tied to a number. The higher the number, the higher the severity. */ enum LogLevel : LogLevelType { - disabled = 0, ///< Use this log level to disable logging entirely. No message should be logged as disabled. trace = 32, ///< Very detailed information, useful for tracking the individual steps of an operation debug = 64, ///< General debugging information info = 96, ///< Noteworthy or periodical events @@ -66,6 +70,7 @@ public: warning = 160, ///< Unexpected events that do not compromise the operability of a function error = 192, ///< Unexpected failure of an operation emergency = 254, ///< Unexpected failure that renders the entire system unusable + disabled = 255, ///< Use this log level to disable logging entirely. No message should be logged as disabled. }; /** @@ -84,7 +89,6 @@ public: */ struct LogEntry { String<LOGGER_MAX_MESSAGE_SIZE> message = ""; ///< The current log message itself, starting from a blank slate - etl::format_spec format; ///< ETL's string format specification LogLevel level; ///< The log level of this message explicit LogEntry(LogLevel level); ///< Create a new LogEntry @@ -131,7 +135,7 @@ public: /** * Store a new log message */ - static void log(LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE>& message); + static void log(LogLevel level, etl::istring & message); }; /** @@ -190,7 +194,7 @@ public: * message will not be logged. This is determined at compile-time. */ template <Logger::LogLevel level> -constexpr inline auto LOG() { +constexpr __attribute__((always_inline)) inline auto LOG() { if constexpr (Logger::isLogged(level)) { return Logger::LogEntry(level); } else { diff --git a/src/Logger.cpp b/src/Logger.cpp index 64bb617f0f7f873360cd101be0d5c4d763fa0009..65584a94db8d744d8664f92ed10b0e3cd8944005 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -1,5 +1,7 @@ #include <Logger.hpp> +etl::format_spec Logger::format; + // Reimplementation of the function for variable C strings template <> Logger::LogEntry& Logger::LogEntry::operator<<(char* value) noexcept { @@ -14,9 +16,7 @@ Logger::LogEntry& Logger::LogEntry::operator<<(const char* value) noexcept { return *this; } -Logger::LogEntry::LogEntry(LogLevel level) : level(level) { - format.precision(3); // Set precision to 3 decimal digits -} +Logger::LogEntry::LogEntry(LogLevel level) : level(level) {} Logger::LogEntry::~LogEntry() { // When the destructor is called, the log message is fully "designed". Now we can finally "display" it to the user. diff --git a/src/Platform/x86/Logger.cpp b/src/Platform/x86/Logger.cpp index 5f6c839f13879b8985358da7b402a939f4558e51..f5ec73d047e0f14dabac0cbd20167add4519e744 100644 --- a/src/Platform/x86/Logger.cpp +++ b/src/Platform/x86/Logger.cpp @@ -7,7 +7,7 @@ #include <iomanip> // The implementation of this function appends ANSI codes that should add colours to a compatible terminal -void Logger::log(Logger::LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE> & message) { +void Logger::log(Logger::LogLevel level, etl::istring & message) { // Get the current time & date std::time_t t = std::time(nullptr); std::tm tm = *std::localtime(&t); diff --git a/test/TestPlatform.cpp b/test/TestPlatform.cpp index 1e50ae0f48833268b8bbb336d9589a9ff41b97d9..beb76de1e0fb393521b3a22fe915de5c1c68f241 100644 --- a/test/TestPlatform.cpp +++ b/test/TestPlatform.cpp @@ -35,7 +35,7 @@ void ErrorHandler::logError(ErrorType errorType) { ServiceTests::addError(ErrorHandler::findErrorSource(errorType), errorType); } -void Logger::log(Logger::LogLevel level, String<LOGGER_MAX_MESSAGE_SIZE> & message) { +void Logger::log(Logger::LogLevel level, etl::istring & message) { // Logs while testing are completely ignored }