c ++中是否有任何日志记录功能可以通过设置debug = True或类似的东西来启用,以便将调试消息打印到stdout?
答案 0 :(得分:1)
通常的技巧是这样的:
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");
答案 1 :(得分:0)
不自动。但是你可以有选择地定义自己的方法。
#ifdef DEBUG
#define DEBUG_MSG(msg) debug(msg)
#else
#define DEBUG_MSG(msg)
#endif