HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BaseLogger.h File Reference

Unified logging base class for all logging implementations. More...

#include "HardwareTypes.h"
#include <cstdarg>
#include <cstdint>
#include <functional>
#include <string>
#include <string_view>
Include dependency graph for BaseLogger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hf_logger_config_t
 Logger configuration structure. More...
 
struct  hf_logger_statistics_t
 Logger statistics structure. More...
 
struct  hf_logger_diagnostics_t
 Logger diagnostics structure. More...
 
struct  hf_log_message_t
 Log message structure. More...
 
class  BaseLogger
 Base logger abstract class. More...
 

Macros

#define HF_LOGGER_ERR_LIST(X)
 HardFOC Logger error codes macro list.
 
#define HF_LOGGER_ERR_ENUM(name, value, description)   name = value,
 Generate logger error enum from macro list.
 
#define X(NAME, VALUE, DESC)
 
#define HF_LOG_ERROR(tag, format, ...)
 Log at ERROR level with file and line information.
 
#define HF_LOG_WARN(tag, format, ...)
 Log at WARN level with file and line information.
 
#define HF_LOG_INFO(tag, format, ...)
 Log at INFO level with file and line information.
 
#define HF_LOG_DEBUG(tag, format, ...)
 Log at DEBUG level with file and line information.
 
#define HF_LOG_VERBOSE(tag, format, ...)
 Log at VERBOSE level with file and line information.
 
#define HF_LOG_IF(condition, level, tag, format, ...)
 Conditional logging macro.
 

Enumerations

enum class  hf_logger_err_t : hf_u32_t {
  LOGGER_SUCCESS = 0 , LOGGER_ERR_FAILURE = 1 , LOGGER_ERR_NOT_INITIALIZED = 2 , LOGGER_ERR_ALREADY_INITIALIZED = 3 ,
  LOGGER_ERR_INVALID_PARAMETER = 4 , LOGGER_ERR_NULL_POINTER = 5 , LOGGER_ERR_OUT_OF_MEMORY = 6 , LOGGER_ERR_INVALID_CONFIGURATION = 7 ,
  LOGGER_ERR_UNSUPPORTED_OPERATION = 8 , LOGGER_ERR_RESOURCE_BUSY = 9 , LOGGER_ERR_RESOURCE_UNAVAILABLE = 10 , LOGGER_ERR_WRITE_FAILURE = 11 ,
  LOGGER_ERR_OUTPUT_BUFFER_FULL = 12 , LOGGER_ERR_FORMAT_ERROR = 13 , LOGGER_ERR_ENCODING_ERROR = 14 , LOGGER_ERR_SYSTEM_ERROR = 15 ,
  LOGGER_ERR_PERMISSION_DENIED = 16 , LOGGER_ERR_OPERATION_ABORTED = 17 , LOGGER_ERR_NOT_SUPPORTED = 18 , LOGGER_ERR_DRIVER_ERROR = 19 ,
  LOGGER_ERR_INVALID_STATE = 20 , LOGGER_ERR_INVALID_ARG = 21 , LOGGER_ERR_TIMEOUT = 22 , LOGGER_ERR_BUFFER_OVERFLOW = 23 ,
  LOGGER_ERR_UNKNOWN = 24
}
 
enum class  hf_log_level_t : hf_u8_t {
  hf_log_level_t::LOG_LEVEL_NONE = 0 , hf_log_level_t::LOG_LEVEL_ERROR = 1 , hf_log_level_t::LOG_LEVEL_WARN = 2 , hf_log_level_t::LOG_LEVEL_INFO = 3 ,
  hf_log_level_t::LOG_LEVEL_DEBUG = 4 , hf_log_level_t::LOG_LEVEL_VERBOSE = 5
}
 Log levels enumeration. More...
 
enum class  hf_log_output_t : hf_u8_t {
  hf_log_output_t::LOG_OUTPUT_NONE = 0 , hf_log_output_t::LOG_OUTPUT_UART = 1 , hf_log_output_t::LOG_OUTPUT_USB = 2 , hf_log_output_t::LOG_OUTPUT_FILE = 3 ,
  hf_log_output_t::LOG_OUTPUT_NETWORK = 4 , hf_log_output_t::LOG_OUTPUT_CUSTOM = 5
}
 Log output destination enumeration. More...
 
enum class  hf_log_format_t : hf_u32_t {
  hf_log_format_t::LOG_FORMAT_NONE = 0 , hf_log_format_t::LOG_FORMAT_TIMESTAMP = (1U << 0) , hf_log_format_t::LOG_FORMAT_LEVEL = (1U << 1) , hf_log_format_t::LOG_FORMAT_TAG = (1U << 2) ,
  hf_log_format_t::LOG_FORMAT_FILE_LINE = (1U << 3) , hf_log_format_t::LOG_FORMAT_FUNCTION = (1U << 4) , hf_log_format_t::LOG_FORMAT_THREAD_ID = (1U << 5) , hf_log_format_t::LOG_FORMAT_COLORS = (1U << 6) ,
  hf_log_format_t::LOG_FORMAT_DEFAULT = LOG_FORMAT_TIMESTAMP | LOG_FORMAT_LEVEL | LOG_FORMAT_TAG
}
 Log format options. More...
 

Functions

hf_log_format_t operator| (hf_log_format_t a, hf_log_format_t b)
 
hf_log_format_t operator& (hf_log_format_t a, hf_log_format_t b)
 
hf_log_format_t operator^ (hf_log_format_t a, hf_log_format_t b)
 
hf_log_format_t operator~ (hf_log_format_t a)
 
constexpr std::string_view HfLoggerErrToString (hf_logger_err_t err) noexcept
 Convert logger error code to string view.
 
const char * HfLogLevelToString (hf_log_level_t level) noexcept
 Convert log level to string.
 
const char * HfLogLevelToShortString (hf_log_level_t level) noexcept
 Convert log level to short string.
 
hf_u64_t HfLoggerGetTimestamp () noexcept
 Get current timestamp in microseconds.
 
hf_u32_t HfLoggerGetThreadId () noexcept
 Get current thread ID.
 

Detailed Description

Unified logging base class for all logging implementations.

This file contains the declaration of the BaseLogger abstract class, which provides a comprehensive logging abstraction that serves as the base for all logging implementations in the HardFOC system. It supports multiple log levels, configurable output destinations, thread-safe operations, and works across different hardware platforms including ESP32, STM32, and other MCUs.

Author
Nebiyu Tadesse
Date
2025
Note
This class is thread-safe and designed for concurrent access.

Macro Definition Documentation

◆ HF_LOG_DEBUG

#define HF_LOG_DEBUG ( tag,
format,
... )
Value:
LogWithLocation(hf_log_level_t::LOG_LEVEL_DEBUG, tag, __FILE__, __LINE__, __FUNCTION__, format, \
##__VA_ARGS__)
@ LOG_LEVEL_DEBUG
Debug, info, warning, and error messages.

Log at DEBUG level with file and line information.

◆ HF_LOG_ERROR

#define HF_LOG_ERROR ( tag,
format,
... )
Value:
LogWithLocation(hf_log_level_t::LOG_LEVEL_ERROR, tag, __FILE__, __LINE__, __FUNCTION__, format, \
##__VA_ARGS__)
@ LOG_LEVEL_ERROR
Error messages only.

Log at ERROR level with file and line information.

◆ HF_LOG_IF

#define HF_LOG_IF ( condition,
level,
tag,
format,
... )
Value:
do { \
if (condition) { \
LogWithLocation(level, tag, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__); \
} \
} while (0)

Conditional logging macro.

◆ HF_LOG_INFO

#define HF_LOG_INFO ( tag,
format,
... )
Value:
LogWithLocation(hf_log_level_t::LOG_LEVEL_INFO, tag, __FILE__, __LINE__, __FUNCTION__, format, \
##__VA_ARGS__)
@ LOG_LEVEL_INFO
Info, warning, and error messages.

Log at INFO level with file and line information.

◆ HF_LOG_VERBOSE

#define HF_LOG_VERBOSE ( tag,
format,
... )
Value:
LogWithLocation(hf_log_level_t::LOG_LEVEL_VERBOSE, tag, __FILE__, __LINE__, __FUNCTION__, \
format, ##__VA_ARGS__)
@ LOG_LEVEL_VERBOSE
All messages including verbose.

Log at VERBOSE level with file and line information.

◆ HF_LOG_WARN

#define HF_LOG_WARN ( tag,
format,
... )
Value:
LogWithLocation(hf_log_level_t::LOG_LEVEL_WARN, tag, __FILE__, __LINE__, __FUNCTION__, format, \
##__VA_ARGS__)
@ LOG_LEVEL_WARN
Warning and error messages.

Log at WARN level with file and line information.

◆ X

#define X ( NAME,
VALUE,
DESC )
Value:
case hf_logger_err_t::NAME: \
return DESC;

Enumeration Type Documentation

◆ hf_logger_err_t

enum class hf_logger_err_t : hf_u32_t
strong
Enumerator
LOGGER_SUCCESS 
LOGGER_ERR_FAILURE 
LOGGER_ERR_NOT_INITIALIZED 
LOGGER_ERR_ALREADY_INITIALIZED 
LOGGER_ERR_INVALID_PARAMETER 
LOGGER_ERR_NULL_POINTER 
LOGGER_ERR_OUT_OF_MEMORY 
LOGGER_ERR_INVALID_CONFIGURATION 
LOGGER_ERR_UNSUPPORTED_OPERATION 
LOGGER_ERR_RESOURCE_BUSY 
LOGGER_ERR_RESOURCE_UNAVAILABLE 
LOGGER_ERR_WRITE_FAILURE 
LOGGER_ERR_OUTPUT_BUFFER_FULL 
LOGGER_ERR_FORMAT_ERROR 
LOGGER_ERR_ENCODING_ERROR 
LOGGER_ERR_SYSTEM_ERROR 
LOGGER_ERR_PERMISSION_DENIED 
LOGGER_ERR_OPERATION_ABORTED 
LOGGER_ERR_NOT_SUPPORTED 
LOGGER_ERR_DRIVER_ERROR 
LOGGER_ERR_INVALID_STATE 
LOGGER_ERR_INVALID_ARG 
LOGGER_ERR_TIMEOUT 
LOGGER_ERR_BUFFER_OVERFLOW 
LOGGER_ERR_UNKNOWN 

Function Documentation

◆ HfLoggerErrToString()

constexpr std::string_view HfLoggerErrToString ( hf_logger_err_t err)
constexprnoexcept

Convert logger error code to string view.

Parameters
errThe error code to convert
Returns
String view of the error description

◆ HfLoggerGetThreadId()

hf_u32_t HfLoggerGetThreadId ( )
noexcept

Get current thread ID.

Returns
hf_u32_t Thread ID

◆ HfLoggerGetTimestamp()

hf_u64_t HfLoggerGetTimestamp ( )
noexcept

Get current timestamp in microseconds.

Returns
hf_u64_t Timestamp in microseconds

◆ HfLogLevelToShortString()

const char * HfLogLevelToShortString ( hf_log_level_t level)
inlinenoexcept

Convert log level to short string.

Parameters
levelLog level
Returns
const char* Short level string

◆ HfLogLevelToString()

const char * HfLogLevelToString ( hf_log_level_t level)
inlinenoexcept

Convert log level to string.

Parameters
levelLog level
Returns
const char* Level string

◆ operator&()

hf_log_format_t operator& ( hf_log_format_t a,
hf_log_format_t b )
inline

◆ operator^()

hf_log_format_t operator^ ( hf_log_format_t a,
hf_log_format_t b )
inline

◆ operator|()

hf_log_format_t operator| ( hf_log_format_t a,
hf_log_format_t b )
inline

◆ operator~()

hf_log_format_t operator~ ( hf_log_format_t a)
inline