跳转至

lib/logger/cfbd_log.h

Classes

Name
struct CFBD_LoggerOperations
struct CFBD_NativeLoggerOperations
struct __CFBD_Logger

Types

Name
enum cfbd_log_level_t
typedef struct __CFBD_Logger CFBD_Logger

Functions

Name
void CFBD_InitLogger(CFBD_Logger * logger, CFBD_NativeLoggerOperations * native_send, void * native_handle, cfbd_log_level_t filter_level, uint8_t * buffer_ptr, uint16_t buffer_sz)
void CFBD_SetFilteredOffLevel(CFBD_Logger * logger, cfbd_log_level_t filter_off_level)

Defines

Name
CFBD_LOG_V(logger_handle, tag, fmt, ...)
CFBD_LOG_D(logger_handle, tag, fmt, ...)
CFBD_LOG_I(logger_handle, tag, fmt, ...)
CFBD_LOG_W(logger_handle, tag, fmt, ...)
CFBD_LOG_E(logger_handle, tag, fmt, ...)
CFBD_LOG_F(logger_handle, tag, fmt, ...)
CFBD_LOGV(handle, fmt, ...)
CFBD_LOGD(handle, fmt, ...)
CFBD_LOGI(handle, fmt, ...)
CFBD_LOGW(handle, fmt, ...)
CFBD_LOGE(handle, fmt, ...)
CFBD_LOGF(handle, fmt, ...)

Types Documentation

enum cfbd_log_level_t

Enumerator Value Description
CFBD_LOG_LEVEL_LOWEST -1
CFBD_LOG_LEVEL_VERBOSE 0
CFBD_LOG_LEVEL_DEBUG
CFBD_LOG_LEVEL_INFO
CFBD_LOG_LEVEL_WARN
CFBD_LOG_LEVEL_ERROR
CFBD_LOG_LEVEL_FATAL
CFBD_LOG_LEVEL_NONE

typedef CFBD_Logger

typedef struct __CFBD_Logger CFBD_Logger;

Functions Documentation

function CFBD_InitLogger

void CFBD_InitLogger(
    CFBD_Logger * logger,
    CFBD_NativeLoggerOperations * native_send,
    void * native_handle,
    cfbd_log_level_t filter_level,
    uint8_t * buffer_ptr,
    uint16_t buffer_sz
)

function CFBD_SetFilteredOffLevel

static inline void CFBD_SetFilteredOffLevel(
    CFBD_Logger * logger,
    cfbd_log_level_t filter_off_level
)

Macros Documentation

define CFBD_LOG_V

#define CFBD_LOG_V(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_VERBOSE,                                        \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOG_D

#define CFBD_LOG_D(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_DEBUG,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOG_I

#define CFBD_LOG_I(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_INFO,                                           \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOG_W

#define CFBD_LOG_W(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_WARN,                                           \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOG_E

#define CFBD_LOG_E(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_ERROR,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOG_F

#define CFBD_LOG_F(
    logger_handle,
    tag,
    fmt,
    ...
)
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_FATAL,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

define CFBD_LOGV

#define CFBD_LOGV(
    handle,
    fmt,
    ...
)
CFBD_LOG_V(handle, NULL, fmt, ##__VA_ARGS__)

define CFBD_LOGD

#define CFBD_LOGD(
    handle,
    fmt,
    ...
)
CFBD_LOG_D(handle, NULL, fmt, ##__VA_ARGS__)

define CFBD_LOGI

#define CFBD_LOGI(
    handle,
    fmt,
    ...
)
CFBD_LOG_I(handle, NULL, fmt, ##__VA_ARGS__)

define CFBD_LOGW

#define CFBD_LOGW(
    handle,
    fmt,
    ...
)
CFBD_LOG_W(handle, NULL, fmt, ##__VA_ARGS__)

define CFBD_LOGE

#define CFBD_LOGE(
    handle,
    fmt,
    ...
)
CFBD_LOG_E(handle, NULL, fmt, ##__VA_ARGS__)

define CFBD_LOGF

#define CFBD_LOGF(
    handle,
    fmt,
    ...
)
CFBD_LOG_F(handle, NULL, fmt, ##__VA_ARGS__)

Source code

#pragma once
#include <stdint.h>

#include "cfbd_define.h"

/*
 * Loggers are Loggers, because they are loggers
 */

typedef enum
{
    CFBD_LOG_LEVEL_LOWEST = -1,
    CFBD_LOG_LEVEL_VERBOSE = 0, /* 详细信息 */
    CFBD_LOG_LEVEL_DEBUG,       /* 调试信息 */
    CFBD_LOG_LEVEL_INFO,        /* 一般信息 */
    CFBD_LOG_LEVEL_WARN,        /* 警告信息 */
    CFBD_LOG_LEVEL_ERROR,       /* 错误信息 */
    CFBD_LOG_LEVEL_FATAL,
    CFBD_LOG_LEVEL_NONE
} cfbd_log_level_t;

typedef struct __CFBD_Logger CFBD_Logger;

typedef struct
{
    void (*log_message)(CFBD_Logger* log_handle,
                        cfbd_log_level_t level,
                        const char* tag,
                        const char* file,
                        int line,
                        const char* fmt,
                        ...);
} CFBD_LoggerOperations;

typedef struct
{
    void (*log_native)(void* native_handle, const char* buffer, const uint16_t buffer_size);
    uint32_t (*timestamp)(void* native_handle); // If, native handle can access
} CFBD_NativeLoggerOperations;

typedef struct __CFBD_Logger
{
    CFBD_LoggerOperations* ops;
    CFBD_NativeLoggerOperations* native_logs; // As expected, dont call these direct

    cfbd_log_level_t filter_off_level;

    uint8_t* buffer_ptr;
    uint16_t buffer_sz;
    void* native_handle;

    CFBD_Bool enable_colorize;
} CFBD_Logger;

void CFBD_InitLogger(CFBD_Logger* logger,
                     CFBD_NativeLoggerOperations* native_send,
                     void* native_handle,
                     cfbd_log_level_t filter_level,
                     uint8_t* buffer_ptr,
                     uint16_t buffer_sz);

static inline void CFBD_SetFilteredOffLevel(CFBD_Logger* logger, cfbd_log_level_t filter_off_level)
{
    logger->filter_off_level = filter_off_level;
}

#define CFBD_LOG_V(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_VERBOSE,                                        \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOG_D(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_DEBUG,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOG_I(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_INFO,                                           \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOG_W(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_WARN,                                           \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOG_E(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_ERROR,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOG_F(logger_handle, tag, fmt, ...)                                                   \
    logger_handle->ops->log_message(logger_handle,                                                 \
                                    CFBD_LOG_LEVEL_FATAL,                                          \
                                    tag,                                                           \
                                    __FILE__,                                                      \
                                    __LINE__,                                                      \
                                    fmt,                                                           \
                                    ##__VA_ARGS__)

#define CFBD_LOGV(handle, fmt, ...) CFBD_LOG_V(handle, NULL, fmt, ##__VA_ARGS__)
#define CFBD_LOGD(handle, fmt, ...) CFBD_LOG_D(handle, NULL, fmt, ##__VA_ARGS__)
#define CFBD_LOGI(handle, fmt, ...) CFBD_LOG_I(handle, NULL, fmt, ##__VA_ARGS__)
#define CFBD_LOGW(handle, fmt, ...) CFBD_LOG_W(handle, NULL, fmt, ##__VA_ARGS__)
#define CFBD_LOGE(handle, fmt, ...) CFBD_LOG_E(handle, NULL, fmt, ##__VA_ARGS__)
#define CFBD_LOGF(handle, fmt, ...) CFBD_LOG_F(handle, NULL, fmt, ##__VA_ARGS__)

Updated on 2026-02-03 at 13:21:55 +0000