Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c++; 是否存在C++中的任何日志记录功能,可以通过设置Debug=true或类似的方式将调试消息打印到STDUT? < P>,通常的技巧是这样的: 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");_C++_Logging - Fatal编程技术网

c++; 是否存在C++中的任何日志记录功能,可以通过设置Debug=true或类似的方式将调试消息打印到STDUT? < P>,通常的技巧是这样的: 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");

c++; 是否存在C++中的任何日志记录功能,可以通过设置Debug=true或类似的方式将调试消息打印到STDUT? < P>,通常的技巧是这样的: 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");,c++,logging,C++,Logging,不是自动的。但是您可以有选择地定义自己的方法 #ifdef DEBUG #define DEBUG_MSG(msg) debug(msg) #else #define DEBUG_MSG(msg) #endif 有,但它会转到stderr。所以根据debug的值,日志将被定义为不同的东西,对吗?对不起,我对这种类型的函数定义有点陌生。没错。#指令是预处理器的一部分;基本上,在编译代码之前,预处理器将对其进行物理重写。如果已定义了DEBUG(通常作为项目设置或切换到命令行编译器),则Log将替换

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

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

有,但它会转到
stderr
。所以根据debug的值,日志将被定义为不同的东西,对吗?对不起,我对这种类型的函数定义有点陌生。没错。
#
指令是预处理器的一部分;基本上,在编译代码之前,预处理器将对其进行物理重写。如果已定义了
DEBUG
(通常作为项目设置或切换到命令行编译器),则
Log
将替换为
writeLog
;如果没有定义,
Log
将被替换为nothing,因此它什么也不做。更糟糕的是,该标准定义了一个符号
NDEBUG
,它会影响
assert
宏。因此,如果希望日志记录和断言位于同一开关上,则可以使用该开关,或者如果
NDEBUG
为false,则可以添加一些代码来定义
DEBUG
,反之亦然。