Files
23Mar25_PrintLOG/program/include/printlog.h
2025-08-04 17:04:56 +08:00

179 lines
5.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: Lucius
* @Date: 2023-03-25 14:05:20
* @LastEditTime: 2023-03-27 17:11:09
* @LastEditors: Lucius
* @Description:
* @FilePath: /23Mar25_PrintLOG/program/include/printlog.h
*/
#ifndef PRINT_LOG_H_
#define PRINT_LOG_H_
#define ERROR_LOG_OK 0 /**< 错误日记ok标识*/
#define ERROR_LOG_SET_TYPE -1 /**< 错误日记设置类型*/
#define PRINT_RUN_MODE 1 /**< 打印运行的模式*/
#define PRINT_PROCESS_MODE 0 /**< 打印进程模式*/
#define PRINT_THREAD_MODE 1 /**< 打印线程模式*/
/** 打印日记的类型*/
enum __PRINT_LOG_TYPE
{
LOG_TYPE_NULL = 0x0, /**< 不打印调试信息 */
LOG_TYPE_ERROR = (1 << 0), /**< 打印错误调试信息 */
LOG_TYPE_WARNING = (1 << 1), /**< 打印警告调试信息 */
LOG_TYPE_INFO = (1 << 2), /**< 打印提示调试信息 */
LOG_TYPE_DEBUG = (1 << 3), /**< 打印调试信息 */
};
enum __PRINT_LOG_DEBUGFLAG
{
dDebugFlag_main = 0,
dDebugFlag_Max
};
void SetDebugFlag(unsigned int tInputDebugFlag);
int HaveDebugFlag(unsigned int tInputDebugFlag);
/**
* \fn int SetLogType(char logType, int enable)
* \brief 设置打印类型
* \param logType [in] 打印信息的类型
* \code
enum __PRINT_LOG_TYPE
{
LOG_TYPE_NULL = 0x0, // 不打印调试信息
LOG_TYPE_ERROR = (1 << 0), // 打印错误调试信息
LOG_TYPE_WARNING = (1 << 1), // 打印警告调试信息
LOG_TYPE_INFO = (1 << 2), // 打印提示调试信息
LOG_TYPE_DEBUG = (1 << 3), // 打印调试信息
};
* \endcode
* \param enable [in] 设置相应类型是否生效 \n
* 1:开启 \n
* 0:关闭
* \return
* 1 : 设置成功 \n
* 0 : 设置失败
* \sa __PRINT_LOG_TYPE
*/
int SetLogType(char logType, int enable);
/**
* \fn void SetLogTypesByParams(char *pParams)
* \brief 通过参数设置打印类型功能类型SetLogType函数。
* \param pParams [in] 打印类型描述参数 \n
* 字符串中包含如下字母 \n
* E:打印错误调试信息 \n
* W:打印警告调试信息 \n
* I打印提示调试信息 \n
* D打印调试信息 \n
* \return 无
*/
void SetLogTypesByParams(char *pParams);
/**
* \fn int SetprocessName(const char *pFileName)
* \brief 设置进程打印的文件名。
* \param pFileName [in] 文件名描述
* \return
* < 0:设置失败 \n
* 0: 设置成功
*/
int SetprocessName(const char *pFileName);
/**
* \fn int SetPrintParameter(int parameterCode, char *parameterValue, int maxValueLen)
* \brief 设置打印库参数。
* \param parameterCode [in] 参数编码
* \code
* #define PRINT_PROCESS_MODE 0 //进程模式
* #define PRINT_THREAD_MODE 1 //线程模式
* \endcode
* \param parameterValue [out] 参数值
* \param maxValueLen [in] 参数最大长度
*
* \return
* < 0设置失败 \n
* 0设置成功
*/
int SetPrintParameter(int parameterCode, int *parameterValue, int maxValueLen);
/**
* \fn int GetLogType(void)
* \brief 获得打印类型
* \param 无
* \return 返回打印类型
*/
int GetLogType(void);
/**
* \fn void PrintLog(enum __PRINT_LOG_DEBUGFLAG debugflag, enum __PRINT_LOG_TYPE logType, const char *pFile, const char *pFunction,
int line, const char *pFormat, ...)
* \brief 打印格式化信息。
* \param logType [in] 打印信息的类型error、warning、info
* \param pFile [in] 打印函数所在的文件名
* \param pFunction [in] 打印代码所在的函数名
* \param line [in] 打印代码所在的文件的行数
* \param pFormat [in] 打印格式化信息
*
* \return 无
*/
void PrintLog(enum __PRINT_LOG_DEBUGFLAG debugflag, enum __PRINT_LOG_TYPE logType, const char *pFile, const char *pFunction,
int line, const char *pFormat, ...);
/**
* \def _PrintLog_(type, fmt...)
* \brief 打印日记
* \param type [in] 类型
* \code
enum __PRINT_LOG_TYPE
{
LOG_TYPE_NULL = 0x0, // 不打印调试信息
LOG_TYPE_ERROR = (1 << 0), // 打印错误调试信息
LOG_TYPE_WARNING = (1 << 1), // 打印警告调试信息
LOG_TYPE_INFO = (1 << 2), // 打印提示调试信息
LOG_TYPE_DEBUG = (1 << 3), // 打印调试信息
};
* \endcode
* \param fmt [in] 格式
*/
#define _PrintLog_(debugflag, type, fmt...) \
PrintLog(debugflag, type, __FILE__, __FUNCTION__, __LINE__, fmt)
/* 打印不同类型信息 */
/**
* \def PrintErr(fmt...)
* \brief 打印错误信息
* \param fmt [in] 格式
* \sa _PrintLog_
*/
#define PrintErr(debugflag, fmt...) _PrintLog_(debugflag, LOG_TYPE_ERROR, fmt)
/**
* \def PrintWarn(fmt...)
* \brief 打印警告信息
* \param fmt [in] 格式
* \sa _PrintLog_
*/
#define PrintWarn(debugflag, fmt...) _PrintLog_(debugflag, LOG_TYPE_WARNING, fmt)
/**
* \def PrintInfo(fmt...)
* \brief 打印信息
* \param fmt [in] 格式
* \sa _PrintLog_
*/
#define PrintInfo(debugflag, fmt...) _PrintLog_(debugflag, LOG_TYPE_INFO, fmt)
/**
* \def PrintDebug(fmt...)
* \brief 打印调试信息
* \param fmt [in] 格式
* \sa _PrintLog_
*/
#define PrintDebug(debugflag, fmt...) _PrintLog_(debugflag, LOG_TYPE_DEBUG, fmt)
#endif /* DEBUGLOG_H_ */