130 lines
3.0 KiB
C
130 lines
3.0 KiB
C
/** @file mrs_log.h
|
|
@brief
|
|
@details
|
|
@version 1.0.0
|
|
@author HuangXin
|
|
@date 2012-11-20
|
|
@copyright Synway
|
|
*/
|
|
|
|
#ifndef MRS_LOG_H_
|
|
#define MRS_LOG_H_
|
|
|
|
#ifndef __KERNEL__
|
|
#include <string.h>
|
|
#endif
|
|
|
|
#define LOG_TAR ("MRS")
|
|
|
|
/** @enum _LOG_LEVEL_
|
|
* 错误值枚举变量
|
|
*/
|
|
typedef enum _LOG_LEVEL_
|
|
{
|
|
LOG_Fatal = (1 << 0),
|
|
LOG_Error = (1 << 1),
|
|
LOG_Warn = (1 << 2),
|
|
LOG_Debug = (1 << 3),
|
|
LOG_Info = (1 << 4),
|
|
LOG_Test = (1 << 5),
|
|
LOG_Unknown = (1 << 6),
|
|
LOG_All = (0xFFFFFFFF),
|
|
LOG_Close = 0x0,
|
|
} LOG_LEVEL;
|
|
|
|
#ifdef DIS_MRS_LOG
|
|
#define LOG_EX(level, format, args...)
|
|
#define LOG_TAG_EX(tag, level, format, args...)
|
|
#define DEBUG_CODE_LINE()
|
|
#define DEBUG_FUNCTION_BEGIN()
|
|
#define DEBUG_FUNCTION_END()
|
|
#else
|
|
/** @var typedef _LOG_LEVEL_ LOG_LEVEL
|
|
* @brief 错误值枚举类型
|
|
*/
|
|
|
|
/*! \def LOG_EX
|
|
\brief 系统日志调试宏标识
|
|
*/
|
|
#define LOG_EX(level, format, args...) (HD_LOG(level, "[%s] - %s(%d):"format, basename_v2(__FILE__), __FUNCTION__, __LINE__, ##args))
|
|
|
|
/*! \def LOG_TAG_EX
|
|
\brief 系统日志调试宏标识
|
|
*/
|
|
#define LOG_TAG_EX(tag, level, format, args...) (HD_LOG(level, "{%s} [%s] %s(%d):"format, tag, basename_v2(__FILE__), __FUNCTION__, __LINE__, ##args))
|
|
|
|
#ifdef __KERNEL__
|
|
/*! @def DEBUG_CODE_LINE
|
|
@brief 输出当前函数名,行号
|
|
*/
|
|
#define DEBUG_CODE_LINE() (LOG_TAG_EX(LOG_TAR, LOG_Debug, "\n"))
|
|
|
|
/*! @def DEBUG_FUNCTION_BEGIN
|
|
@brief 函数入口标志
|
|
*/
|
|
#define DEBUG_FUNCTION_BEGIN() (LOG_TAG_EX(LOG_TAR, LOG_Debug, "+++++\n"))
|
|
|
|
/*! @def DEBUG_FUNCTION_END
|
|
@brief 函数出口标志
|
|
*/
|
|
#define DEBUG_FUNCTION_END() (LOG_TAG_EX(LOG_TAR, LOG_Debug, "-----\n"))
|
|
|
|
#else
|
|
|
|
/*! @def DEBUG_CODE_LINE
|
|
@brief 输出当前函数名,行号
|
|
*/
|
|
#define DEBUG_CODE_LINE() (LOG_EX(LOG_Debug, "\n"))
|
|
|
|
/*! @def DEBUG_FUNCTION_BEGIN
|
|
@brief 函数入口标志
|
|
*/
|
|
#define DEBUG_FUNCTION_BEGIN() (LOG_EX(LOG_Debug, "+++++\n"))
|
|
|
|
/*! @def DEBUG_FUNCTION_END
|
|
@brief 函数出口标志
|
|
*/
|
|
#define DEBUG_FUNCTION_END() (LOG_EX(LOG_Debug, "-----\n"))
|
|
#endif
|
|
|
|
/**
|
|
* @brief 输出调试信息
|
|
* @param level 调试信息开关
|
|
* @param pMsg 调试信息内容
|
|
*/
|
|
void HD_LOG(LOG_LEVEL level, const char* pMsg, ...);
|
|
|
|
/**
|
|
* @brief 设置调试等级
|
|
* @param level 调试等级
|
|
* @param iEnable 1 打开调试等级, 0 关闭调试等级
|
|
*/
|
|
void HD_EnableLogLevel(LOG_LEVEL level, int iEnable);
|
|
|
|
#ifndef __KERNEL__
|
|
/**
|
|
* @brief 初始化系统日志功能
|
|
* @param pLogTag 系统日志标志
|
|
* @param pPath 系统日志保存路径
|
|
* @param bEnable 打开/关闭调试信息
|
|
*/
|
|
void HD_InitLOG(const char* pLogTag, const char* pPath, int bEnable);
|
|
|
|
/**
|
|
* @brief 判断文件、路径是否存在
|
|
* @param pPath - 文件路径
|
|
* @return int 存在返回 1, 否则返回 0;
|
|
*/
|
|
int HD_IsFileExist(const char* pPath);
|
|
|
|
#endif
|
|
|
|
/* Return the last part of a pathname */
|
|
static inline const char* basename_v2(const char* path)
|
|
{
|
|
const char* tail = strrchr(path, '/');
|
|
return tail ? tail + 1 : path;
|
|
}
|
|
#endif
|
|
#endif /* MRS_LOG_H_ */
|