Files
wordclock/code/main/platform/inc/logger.h
T
Matthias Mitscherlich a0d13f08c1 Started with a blank main file
- Added GPIO handling
- Added a logger class with additional static debug log handling

Tested, functional
2024-03-11 15:45:48 +01:00

179 lines
5.7 KiB
C++

// --------------------------------------------------------------------------------------------------------------------
/// \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 <stdint.h>
#include <list>
#include <string>
#include <cstring>
// ProjectIncludes
// All include files that are provided by the project
#include <ISerialBus.h>
// --------------------------------------------------------------------------------------------------------------------
// Constant and macro definitions
// --------------------------------------------------------------------------------------------------------------------
#define ENABLE_SERIAL_LOGGING
#if defined(ENABLE_SERIAL_LOGGING)
#define LOGGER_LOG(severity,...) \
debugLogger.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<uint8_t>& serialPort);
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);
void composeLogQueueItem(struct LogQueueItem* logQueueItem, std::string fileName, std::string functionName,
int lineNumber, LogType logType, std::string context);
std::list<struct typeParameters> typeParameterList;
std::list<struct LogQueueItem> queue;
ISerialBus<uint8_t>& port;
uint32_t queuesize;
uint32_t numberOfLostMessages;
};
/** @} */
#endif /* MAIN_PLATFORM_INC_LOGGER_H_ */