45#define HF_LOGGER_ERR_LIST(X) \
47 X(LOGGER_SUCCESS, 0, "Success") \
50 X(LOGGER_ERR_FAILURE, 1, "General failure") \
51 X(LOGGER_ERR_NOT_INITIALIZED, 2, "Not initialized") \
52 X(LOGGER_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
53 X(LOGGER_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
54 X(LOGGER_ERR_NULL_POINTER, 5, "Null pointer") \
55 X(LOGGER_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
58 X(LOGGER_ERR_INVALID_CONFIGURATION, 7, "Invalid configuration") \
59 X(LOGGER_ERR_UNSUPPORTED_OPERATION, 8, "Unsupported operation") \
60 X(LOGGER_ERR_RESOURCE_BUSY, 9, "Resource busy") \
61 X(LOGGER_ERR_RESOURCE_UNAVAILABLE, 10, "Resource unavailable") \
64 X(LOGGER_ERR_WRITE_FAILURE, 11, "Write failure") \
65 X(LOGGER_ERR_OUTPUT_BUFFER_FULL, 12, "Output buffer full") \
66 X(LOGGER_ERR_FORMAT_ERROR, 13, "Format error") \
67 X(LOGGER_ERR_ENCODING_ERROR, 14, "Encoding error") \
70 X(LOGGER_ERR_SYSTEM_ERROR, 15, "System error") \
71 X(LOGGER_ERR_PERMISSION_DENIED, 16, "Permission denied") \
72 X(LOGGER_ERR_OPERATION_ABORTED, 17, "Operation aborted") \
75 X(LOGGER_ERR_NOT_SUPPORTED, 18, "Operation not supported") \
76 X(LOGGER_ERR_DRIVER_ERROR, 19, "Driver error") \
77 X(LOGGER_ERR_INVALID_STATE, 20, "Invalid state") \
78 X(LOGGER_ERR_INVALID_ARG, 21, "Invalid argument") \
79 X(LOGGER_ERR_TIMEOUT, 22, "Timeout") \
80 X(LOGGER_ERR_BUFFER_OVERFLOW, 23, "Buffer overflow") \
81 X(LOGGER_ERR_UNKNOWN, 24, "Unknown error")
87#define HF_LOGGER_ERR_ENUM(name, value, description) name = value,
89#undef HF_LOGGER_ERR_ENUM
226#define X(NAME, VALUE, DESC) \
227 case hf_logger_err_t::NAME: \
303#define HF_LOG_ERROR(tag, format, ...) \
304 LogWithLocation(hf_log_level_t::LOG_LEVEL_ERROR, tag, __FILE__, __LINE__, __FUNCTION__, format, \
310#define HF_LOG_WARN(tag, format, ...) \
311 LogWithLocation(hf_log_level_t::LOG_LEVEL_WARN, tag, __FILE__, __LINE__, __FUNCTION__, format, \
317#define HF_LOG_INFO(tag, format, ...) \
318 LogWithLocation(hf_log_level_t::LOG_LEVEL_INFO, tag, __FILE__, __LINE__, __FUNCTION__, format, \
324#define HF_LOG_DEBUG(tag, format, ...) \
325 LogWithLocation(hf_log_level_t::LOG_LEVEL_DEBUG, tag, __FILE__, __LINE__, __FUNCTION__, format, \
331#define HF_LOG_VERBOSE(tag, format, ...) \
332 LogWithLocation(hf_log_level_t::LOG_LEVEL_VERBOSE, tag, __FILE__, __LINE__, __FUNCTION__, \
333 format, ##__VA_ARGS__)
338#define HF_LOG_IF(condition, level, tag, format, ...) \
341 LogWithLocation(level, tag, __FILE__, __LINE__, __FUNCTION__, format, ##__VA_ARGS__); \
479 va_list args) noexcept = 0;
493 hf_u32_t line, const
char* function, const
char* format,
559 hf_u32_t max_length) const noexcept = 0;
572 bool detailed = true) const noexcept = 0;
581 bool detailed = true) const noexcept = 0;
590 bool detailed = true) const noexcept = 0;
const char * HfLogLevelToShortString(hf_log_level_t level) noexcept
Convert log level to short string.
Definition BaseLogger.h:265
hf_u32_t HfLoggerGetThreadId() noexcept
Get current thread ID.
hf_log_format_t operator|(hf_log_format_t a, hf_log_format_t b)
Definition BaseLogger.h:134
hf_u64_t HfLoggerGetTimestamp() noexcept
Get current timestamp in microseconds.
hf_log_format_t operator&(hf_log_format_t a, hf_log_format_t b)
Definition BaseLogger.h:138
#define X(NAME, VALUE, DESC)
hf_log_format_t operator~(hf_log_format_t a)
Definition BaseLogger.h:146
hf_logger_err_t
Definition BaseLogger.h:88
const char * HfLogLevelToString(hf_log_level_t level) noexcept
Convert log level to string.
Definition BaseLogger.h:241
hf_log_format_t operator^(hf_log_format_t a, hf_log_format_t b)
Definition BaseLogger.h:142
constexpr std::string_view HfLoggerErrToString(hf_logger_err_t err) noexcept
Convert logger error code to string view.
Definition BaseLogger.h:224
Platform-agnostic hardware type definitions for the HardFOC system.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
uint64_t hf_u64_t
Platform-agnostic 64-bit unsigned integer type.
Definition HardwareTypes.h:58
Base logger abstract class.
Definition BaseLogger.h:358
virtual hf_logger_err_t PrintStatus(const char *tag=nullptr, bool detailed=true) const noexcept=0
Print both statistics and diagnostics.
virtual hf_logger_err_t GetLastError() const noexcept=0
Get last error code.
virtual bool EnsureInitialized() noexcept=0
Ensure logger is initialized (lazy initialization)
virtual hf_logger_err_t Debug(const char *tag, const char *format,...) noexcept=0
Log a message at DEBUG level.
virtual hf_logger_err_t ResetDiagnostics() noexcept=0
Reset diagnostics.
virtual hf_logger_err_t Flush() noexcept=0
Flush any buffered output.
virtual hf_logger_err_t GetStatistics(hf_logger_statistics_t &statistics) const noexcept=0
Get logger statistics.
virtual hf_logger_err_t ResetStatistics() noexcept=0
Reset statistics.
virtual hf_logger_err_t Error(const char *tag, const char *format,...) noexcept=0
Log a message at ERROR level.
virtual hf_logger_err_t LogWithLocation(hf_log_level_t level, const char *tag, const char *file, hf_u32_t line, const char *function, const char *format,...) noexcept=0
Log a message with file and line information.
virtual bool IsHealthy() const noexcept=0
Check if logger is healthy.
virtual hf_logger_err_t Deinitialize() noexcept=0
Deinitialize the logger.
virtual ~BaseLogger() noexcept=default
Virtual destructor.
virtual hf_logger_err_t Info(const char *tag, const char *format,...) noexcept=0
Log a message at INFO level.
virtual hf_logger_err_t GetLogLevel(const char *tag, hf_log_level_t &level) const noexcept=0
Get log level for a specific tag.
virtual hf_logger_err_t Verbose(const char *tag, const char *format,...) noexcept=0
Log a message at VERBOSE level.
virtual hf_logger_err_t PrintStatistics(const char *tag=nullptr, bool detailed=true) const noexcept=0
Print statistics to log output.
virtual hf_logger_err_t SetLogLevel(const char *tag, hf_log_level_t level) noexcept=0
Set log level for a specific tag.
virtual hf_logger_err_t LogV(hf_log_level_t level, const char *tag, const char *format, va_list args) noexcept=0
Log a message with va_list (for internal use)
virtual bool IsInitialized() const noexcept=0
Check if logger is initialized.
virtual hf_logger_err_t PrintDiagnostics(const char *tag=nullptr, bool detailed=true) const noexcept=0
Print diagnostics to log output.
virtual hf_logger_err_t Warn(const char *tag, const char *format,...) noexcept=0
Log a message at WARN level.
virtual hf_logger_err_t Initialize(const hf_logger_config_t &config) noexcept=0
Initialize the logger.
virtual hf_logger_err_t Log(hf_log_level_t level, const char *tag, const char *format,...) noexcept=0
Log a message at specified level.
virtual hf_logger_err_t GetLastErrorMessage(char *message, hf_u32_t max_length) const noexcept=0
Get last error message.
virtual hf_logger_err_t GetDiagnostics(hf_logger_diagnostics_t &diagnostics) const noexcept=0
Get logger diagnostics.
virtual bool IsLevelEnabled(hf_log_level_t level, const char *tag=nullptr) const noexcept=0
Check if a log level is enabled for a tag.
hf_log_output_t
Log output destination enumeration.
Definition BaseLogger.h:108
hf_log_format_t
Log format options.
Definition BaseLogger.h:121
#define HF_LOGGER_ERR_LIST(X)
HardFOC Logger error codes macro list.
Definition BaseLogger.h:45
#define HF_LOGGER_ERR_ENUM(name, value, description)
Generate logger error enum from macro list.
Definition BaseLogger.h:87
hf_log_level_t
Log levels enumeration.
Definition BaseLogger.h:95
@ LOG_OUTPUT_NETWORK
Network output.
@ LOG_OUTPUT_USB
USB CDC output.
@ LOG_OUTPUT_UART
UART serial output.
@ LOG_OUTPUT_FILE
File system output.
@ LOG_OUTPUT_CUSTOM
Custom output callback.
@ LOG_OUTPUT_NONE
No output.
@ LOG_FORMAT_FUNCTION
Include function name.
@ LOG_FORMAT_COLORS
Include ANSI colors.
@ LOG_FORMAT_LEVEL
Include log level.
@ LOG_FORMAT_FILE_LINE
Include file and line.
@ LOG_FORMAT_NONE
No formatting.
@ LOG_FORMAT_THREAD_ID
Include thread ID.
@ LOG_FORMAT_TAG
Include tag.
@ LOG_FORMAT_TIMESTAMP
Include timestamp.
@ LOG_LEVEL_WARN
Warning and error messages.
@ LOG_LEVEL_VERBOSE
All messages including verbose.
@ LOG_LEVEL_ERROR
Error messages only.
@ LOG_LEVEL_INFO
Info, warning, and error messages.
@ LOG_LEVEL_DEBUG
Debug, info, warning, and error messages.
@ LOG_LEVEL_NONE
No logging.
Log message structure.
Definition BaseLogger.h:203
const char * file
Source file.
Definition BaseLogger.h:207
hf_u32_t thread_id
Thread ID.
Definition BaseLogger.h:211
hf_log_level_t level
Log level.
Definition BaseLogger.h:204
const char * tag
Message tag.
Definition BaseLogger.h:205
const char * function
Function name.
Definition BaseLogger.h:209
const char * message
Message content.
Definition BaseLogger.h:206
hf_u32_t message_length
Message length.
Definition BaseLogger.h:212
hf_u64_t timestamp
Timestamp.
Definition BaseLogger.h:210
hf_u32_t line
Source line.
Definition BaseLogger.h:208
Logger configuration structure.
Definition BaseLogger.h:154
hf_log_level_t default_level
Default log level.
Definition BaseLogger.h:155
bool enable_performance_monitoring
Enable performance monitoring.
Definition BaseLogger.h:162
bool enable_thread_safety
Enable thread safety.
Definition BaseLogger.h:161
std::function< void(const char *, hf_u32_t) custom_output_callback)
Custom output callback.
Definition BaseLogger.h:163
hf_u32_t flush_interval_ms
Flush interval in milliseconds.
Definition BaseLogger.h:160
hf_log_format_t format_options
Format options.
Definition BaseLogger.h:157
hf_u32_t buffer_size
Internal buffer size.
Definition BaseLogger.h:159
hf_u32_t max_message_length
Maximum message length.
Definition BaseLogger.h:158
hf_log_output_t output_destination
Output destination.
Definition BaseLogger.h:156
Logger diagnostics structure.
Definition BaseLogger.h:187
char last_error_message[256]
Last error message.
Definition BaseLogger.h:196
hf_logger_err_t last_error
Last error code.
Definition BaseLogger.h:190
hf_u32_t error_recovery_count
Error recovery count.
Definition BaseLogger.h:193
hf_u64_t last_health_check
Last health check timestamp.
Definition BaseLogger.h:195
bool is_initialized
Initialization status.
Definition BaseLogger.h:188
bool is_healthy
Health status.
Definition BaseLogger.h:189
hf_u64_t uptime_seconds
Uptime in seconds.
Definition BaseLogger.h:194
hf_u64_t last_error_timestamp
Last error timestamp.
Definition BaseLogger.h:191
hf_u32_t consecutive_errors
Consecutive error count.
Definition BaseLogger.h:192
Logger statistics structure.
Definition BaseLogger.h:170
hf_u64_t last_message_timestamp
Timestamp of last message.
Definition BaseLogger.h:178
hf_u64_t total_bytes_written
Total bytes written.
Definition BaseLogger.h:173
hf_u64_t buffer_overflows
Number of buffer overflows.
Definition BaseLogger.h:176
hf_u64_t max_message_length_seen
Maximum message length seen.
Definition BaseLogger.h:180
hf_u64_t messages_by_level[6]
Messages by level (indexed by hf_log_level_t)
Definition BaseLogger.h:172
hf_u64_t average_message_length
Average message length.
Definition BaseLogger.h:179
hf_u64_t performance_monitor_calls
Number of performance monitor calls.
Definition BaseLogger.h:177
hf_u64_t format_errors
Number of format errors.
Definition BaseLogger.h:175
hf_u64_t write_errors
Number of write errors.
Definition BaseLogger.h:174
hf_u64_t total_messages
Total messages logged.
Definition BaseLogger.h:171