小烦恼
有时候写超级小的模块,打印不够规范…
需求1:打印规范
需求2:编译控制
不需要通过控制台命令放开打印
实现
#define dbg 0
#define inf 1
#define wrn 2
#define err 3
#define crt 4
#define LOG_LEVEL dbg
#define _Log(mod, lv, fmt, ...) \
do{ \
if (lv>=LOG_LEVEL) {\
printf("[%s][%s][%s][%d]:" fmt "\n", mod, #lv, __func__, __LINE__, ##__VA_ARGS__); \
}\
} while(0)
#endif
__file__的名称太长,可以自定义__filename__宏,在编译脚本中输入宏
Makefile:
CXX_FLAGS+=-D__FILENAME__='\"$(subst $(SOURCE_PREFIX)/,,$(abspath $<))\"'"
cmake:
# 2选1
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
# 2选1
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='"$(notdir $<)"'")