用下面的方法在程序中写log信息很好,log中包含了文件名、函数名、行号。
- #include <stdio.h>
- #define LOG_DEBUG "DEBUG"
- #define LOG_TRACE "TRACE"
- #define LOG_ERROR "ERROR"
- #define LOG_INFO "INFOR"
- #define LOG_CRIT "CRTCL"
- #define LOG(level, format, ...) \
- do { \
- fprintf(stderr, "[%s|%s@%s,%d] " format "\n", \
- level, __func__, __FILE__, __LINE__, ##__VA_ARGS__ ); \
- } while (0)
-
- int main()
- {
- LOG(LOG_DEBUG, "a=%d", 10);
- return 0;
- }
或者:
- #define DBG(format, args...) fprintf(stderr, "[%s|%s@%s,%d] " format "\n", APP_NAME, __FUNCTION__, __FILE__, __LINE__, ## args );
阅读(619) | 评论(0) | 转发(0) |