c++中的logger.debug功能

logger.debug functionality in c++

本文关键字:功能 debug logger 中的 c++      更新时间:2023-10-16

c++中是否有任何日志记录功能可以通过设置debug=True或类似的设置来启用,以将调试消息打印到stdout?

通常的技巧如下:

void writeLog(const char* message); // Define elsewhere to do your logging
#ifdef DEBUG
#define Log(x) writeLog(x)
#else
#define Log(x)
#endif
// Somewhere in your main code
Log("This message is only seen if DEBUG is defined at compilation");

不自动。但是你可以有选择地定义你自己的方法。

#ifdef DEBUG
#define DEBUG_MSG(msg) debug(msg)
#else
#define DEBUG_MSG(msg)
#endif