JZsdk_Logger.h 4.1 KB
/**
 ********************************************************************
 * @file   JZsdk_Logger.h
 *          
 *
 *********************************************************************
 */

/* Define to prevent recursive inclusion 避免重定义 -------------------------------------*/
#ifndef JZSDK_LOGGER_H
#define JZSDK_LOGGER_H

/* Includes ------------------------------------------------------------------*/
#include "JZsdk_Base/JZsdk_Code/JZsdk_Code.h"

#ifdef __cplusplus
extern "C" {
#endif



/* Exported types ------------------------------------------------------------*/


typedef enum {
    JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR = 0, /*!< Logger console error level. The method and level of the console are
                                                  associated with each other. If the level of the registered console
                                                  method is lower than this level, the level interface will not be
                                                  printed successfully. */
    JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN = 1, /*!< Logger console warning level.The method and level of the console are
                                                    associated with each other. If the level of the registered console
                                                    method is lower than this level, the level interface will not be
                                                    printed successfully. */
    JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO = 2, /*!< Logger console info level. The method and level of the console are
                                                 associated with each other. If the level of the registered console
                                                 method is lower than this level, the level interface will not be
                                                 printed successfully. */
    JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG = 3, /*!< Logger console debug level. The method and level of the console are
                                                  associated with each other. If the level of the registered console
                                                  method is lower than this level, the level interface will not be
                                                  printed successfully. */
} E_JZsdkConsoleLogLevel;

/**
* @brief The console method that needs to be registered.
* @note  Before registering the console method, you need to test the methods that need to be registered to ensure
*        that they can be used normally.
*/
typedef T_JZsdkReturnCode (*JZsdk_ConsoleFunc)(const JZ_U8 *data, JZ_U16 dataLen);

/**
 * @brief Logger console content.
 */
typedef struct {
    JZsdk_ConsoleFunc func;
    JZ_U8 consoleLevel;
    bool isSupportColor;
} T_JZsdkLoggerConsole;

/* Exported functions --------------------------------------------------------*/
void JZsdk_UserLogOutput(E_JZsdkConsoleLogLevel level, const char *fmt, ...);
void JZsdk_User_OutputHex(E_JZsdkConsoleLogLevel level, const char *fmt, ...);
T_JZsdkReturnCode JZsdk_Logger_AddPrintConsole(T_JZsdkLoggerConsole *console);
T_JZsdkReturnCode JZsdk_Logger_AddRecordConsole(T_JZsdkLoggerConsole *console);

T_JZsdkReturnCode JZsdk_LoggerInit();

/* Exported constants --------------------------------------------------------*/
#define JZSDK_LOG_DEBUG(fmt, ...)    \
        JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_DEBUG, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__)
#define JZSDK_LOG_INFO(fmt, ...)     \
        JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__)
#define JZSDK_LOG_WARN(fmt, ...)     \
        JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_WARN, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__)
#define JZSDK_LOG_ERROR(fmt, ...)    \
        JZsdk_UserLogOutput(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_ERROR, "[%s:%d) " fmt, __FUNCTION__, __LINE__ , ##__VA_ARGS__)
#define JZSDK_LOG_OUTPUTHEX(fmt, ...)    \
        JZsdk_User_OutputHex(JZSDK_LOGGER_CONSOLE_LOG_LEVEL_INFO, "" fmt , ##__VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif 
/************************ (C) COPYRIGHT JZSDK Innovations *******END OF FILE******/