// -------------------------------------------------------------------------------------------------------------------- /// \file logger.h /// \brief File description // -------------------------------------------------------------------------------------------------------------------- // // vbchaos software design // // -------------------------------------------------------------------------------------------------------------------- /// $Revision: $ /// $Author: $ /// $Date: $ // (c) 2023 vbchaos // -------------------------------------------------------------------------------------------------------------------- #ifndef MAIN_PLATFORM_INC_LOGGER_H_ #define MAIN_PLATFORM_INC_LOGGER_H_ /** * logger implementation * \defgroup logger * \brief {group_description} * \addtogroup {Layer} * * Detailed description * @{ */ // -------------------------------------------------------------------------------------------------------------------- // Include files // -------------------------------------------------------------------------------------------------------------------- // CompilerIncludes // All include files that are provided by the compiler directly #include #include #include #include // ProjectIncludes // All include files that are provided by the project #include // -------------------------------------------------------------------------------------------------------------------- // Constant and macro definitions // -------------------------------------------------------------------------------------------------------------------- #define ENABLE_SERIAL_LOGGING #if defined(ENABLE_SERIAL_LOGGING) #define LOGGER_LOG(severity,...) \ logger::log(__FILE__, __func__, __LINE__, severity, ##__VA_ARGS__) #else #define LOGGER_LOG(severity, message) #endif /** * Logs an print message * \memberof Logger */ #define LOGGER_PRINT(...) LOGGER_LOG(logger::LogType::LOGTYPE_PRINT, ##__VA_ARGS__) /** * Logs an debug message * \memberof Logger */ #define LOGGER_DEBUG(...) LOGGER_LOG(logger::LogType::LOGTYPE_DEBUG, ##__VA_ARGS__) /** * Logs an info message * \memberof Logger */ #define LOGGER_INFO(...) LOGGER_LOG(logger::LogType::LOGTYPE_INFO, ##__VA_ARGS__) /** * Logs an warning message * \memberof Logger */ #define LOGGER_WARNING(...) LOGGER_LOG(logger::LogType::LOGTYPE_WARNING, ##__VA_ARGS__) /** * Logs an success message * \memberof Logger */ #define LOGGER_SUCCESS(...) LOGGER_LOG(logger::LogType::LOGTYPE_SUCCESS, ##__VA_ARGS__) /** * Logs an error message * \memberof Logger */ #define LOGGER_ERROR(...) LOGGER_LOG(logger::LogType::LOGTYPE_ERROR, ##__VA_ARGS__) // -------------------------------------------------------------------------------------------------------------------- // Type definitions. // -------------------------------------------------------------------------------------------------------------------- //class logger; //extern logger debugLogger; // -------------------------------------------------------------------------------------------------------------------- // Function declarations // -------------------------------------------------------------------------------------------------------------------- class logger { // ----------------------------------------------------------------------------------------------------------------- // Public Section // ----------------------------------------------------------------------------------------------------------------- public: typedef enum { LOGTYPE_PRINT, /**< Raw print */ LOGTYPE_DEBUG, /**< Debug information only; will not be stored on SD-card */ LOGTYPE_INFO, /**< Informational messages of important events */ LOGTYPE_WARNING, /**< Recoverable fault */ LOGTYPE_SUCCESS, /**< A specific success message */ LOGTYPE_ERROR /**< Unrecoverable fault */ } LogType; // Class Constructor logger(uint32_t queuesize, ISerialBus& serialPort); static FunctionStatus log(const char* fileName, const char* functionName, int lineNumber, LogType logType, const char* format, ...); // The Logger task - should be called by the system scheduler regularly void task(); // ----------------------------------------------------------------------------------------------------------------- // Protected Section // ----------------------------------------------------------------------------------------------------------------- protected: // ----------------------------------------------------------------------------------------------------------------- // Private Section // ----------------------------------------------------------------------------------------------------------------- private: struct LogQueueItem { std::string fileName; std::string functionName; std::string context; uint32_t lineNumber; LogType logType; }; struct typeParameters { LogType logType; std::string vt100Prefix; std::string logPrefix; std::string vt100Postfix; }; void composeTypeParameterList(void); static void composeLogQueueItem(struct LogQueueItem* logQueueItem, const std::string& fileName, const std::string& functionName, int lineNumber, LogType logType, const std::string& context); std::list typeParameterList; static std::list queue; ISerialBus& port; static uint32_t queuesize; static uint32_t numberOfLostMessages; static bool overflowRecovery; }; /** @} */ #endif /* MAIN_PLATFORM_INC_LOGGER_H_ */