hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
ifx-logger.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 Infineon Technologies AG
2// SPDX-License-Identifier: MIT
3
8#ifndef IFX_LOGGER_H
9#define IFX_LOGGER_H
10
11#include <stdarg.h>
12#include <stddef.h>
13#include <stdint.h>
14
15#include "infineon/ifx-error.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
24#define LIB_LOGGER UINT8_C(0x0C)
25
30#define IFX_LOGGER_INITIALIZE UINT8_C(0x01)
31
36#define IFX_LOGGER_LOG UINT8_C(0x02)
37
41#define IFX_LOGGER_SET_LEVEL UINT8_C(0x03)
42
49#define IFX_LOGGER_FORMAT_ERROR 0x01u
50
51// Forward declaration only
52typedef struct ifx_logger ifx_logger_t;
53
57typedef enum
58{
63
68
73
78
84
99
124ifx_status_t ifx_logger_log(const ifx_logger_t *self, const char *source,
125 ifx_log_level level, const char *formatter, ...);
126
153ifx_status_t ifx_logger_log_bytes(const ifx_logger_t *self, const char *source,
154 ifx_log_level level, const char *msg,
155 const uint8_t *data, size_t data_len,
156 const char *delimiter);
157
170typedef ifx_status_t (*ifx_logger_log_callback_t)(const ifx_logger_t *self,
171 const char *source,
172 ifx_log_level level,
173 const char *message);
174
185ifx_status_t ifx_logger_set_level(ifx_logger_t *self, ifx_log_level level);
186
199typedef ifx_status_t (*ifx_logger_set_level_callback_t)(ifx_logger_t *self,
200 ifx_log_level level);
201
214void ifx_logger_destroy(ifx_logger_t *self);
215
224typedef void (*ifx_logger_destroy_callback_t)(ifx_logger_t *self);
225
237void ifx_logger_set_default(ifx_logger_t *logger);
238
244extern ifx_logger_t *ifx_logger_default;
245
250struct ifx_logger
251{
259
270
280
288
294 void *_data;
295};
296
297#ifdef __cplusplus
298}
299#endif
300
301#endif // IFX_LOGGER_H
Infineon specific error code creation and parsing.
uint32_t ifx_status_t
Custom return code type used by all Infineon host software libraries.
Definition ifx-error.h:91
ifx_status_t(* ifx_logger_set_level_callback_t)(ifx_logger_t *self, ifx_log_level level)
Implementation specific log level setter.
Definition ifx-logger.h:197
ifx_log_level
Log level for filtering messages to actually be logged.
Definition ifx-logger.h:58
@ IFX_LOG_WARN
Information that warns of potential problems.
Definition ifx-logger.h:72
@ IFX_LOG_INFO
Information that help trace the program's normal execution flow.
Definition ifx-logger.h:67
@ IFX_LOG_FATAL
Information about non-recoverable errors.
Definition ifx-logger.h:82
@ IFX_LOG_ERROR
Information about (recoverable) errors.
Definition ifx-logger.h:77
@ IFX_LOG_DEBUG
Debug information for finding problems in library.
Definition ifx-logger.h:62
ifx_status_t(* ifx_logger_log_callback_t)(const ifx_logger_t *self, const char *source, ifx_log_level level, const char *message)
Implementation specific log function.
Definition ifx-logger.h:168
void(* ifx_logger_destroy_callback_t)(ifx_logger_t *self)
Implementation specific destructor.
Definition ifx-logger.h:222
ifx_logger_t * ifx_logger_default
Default Logger instance to be used.
Generic Logger object used to decapsulate concrete implementation from interface.
Definition ifx-logger.h:249
void * _data
Private member for generic logger data as void*.
Definition ifx-logger.h:292
ifx_status_t ifx_logger_initialize(ifx_logger_t *self)
Initializes Logger object by setting all members to valid (but potentially unusable) values.
ifx_status_t ifx_logger_log(const ifx_logger_t *self, const char *source, ifx_log_level level, const char *formatter,...)
Log formatted message.
ifx_log_level _level
Private member for minimum log level used for filtering messages.
Definition ifx-logger.h:285
void ifx_logger_set_default(ifx_logger_t *logger)
Sets default Logger to be used.
void ifx_logger_destroy(ifx_logger_t *self)
Frees memory associated with Logger object (but not object itself).
ifx_logger_log_callback_t _log
Private logging function for concrete implementation.
Definition ifx-logger.h:256
ifx_logger_destroy_callback_t _destructor
Private destructor if further cleanup is necessary.
Definition ifx-logger.h:277
ifx_logger_set_level_callback_t _set_level
Private function to set log level.
Definition ifx-logger.h:267
ifx_status_t ifx_logger_set_level(ifx_logger_t *self, ifx_log_level level)
All messages with level lower than level shall be discarded by the logger.
ifx_status_t ifx_logger_log_bytes(const ifx_logger_t *self, const char *source, ifx_log_level level, const char *msg, const uint8_t *data, size_t data_len, const char *delimiter)
Extension of ifx_logger_log() for logging byte arrays.