您的位置:首页 > 其它

ACE 示例中的 ACE_DEBUG 不在窗口输出信息的原因

2014-06-11 11:15 399 查看
在ACE 中,很多示例里的 ACE_DEBUG 都不在窗口打印信息,查了好久,原来是 ACE_START_TEST 作祟。

下面以 ACE-6.0.0 里的Log_Msg_Test 程序为例讲解原因。

Log_Msg_Test.cpp 文件的主函数(代码所在目录:\ACE-6.0.0\ACE_wrappers\tests):

// Main function.

int
run_main (int argc, ACE_TCHAR *argv[])
{

ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("before ACE_START_TEST.\n"))); // 这个ACE_DEBUG因为放在ACE_START_TEST的前面,可以在窗口打印信息。

ACE_START_TEST (ACE_TEXT ("Log_Msg_Test"));  // 不把这句屏蔽掉,后面的 ACE_DEBUG 不会在窗口打印信息。

ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("after ACE_START_TEST.\n")));

int status = 0;

ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** running ostream test\n")));

// Test the <ACE_Log_Msg> abstraction wrt writing to stderr and to a
// file.
test_ostream ();

ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("%M **** running callback test\n")));

// Test the <ACE_Log_Msg> callback mechanism.
test_callbacks ();

ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** running features test\n")));

// Test various features of the <ACE_Log_Msg>.
test_log_msg_features ((argc > 0 ? argv[0] : ACE_TEXT ("program")));

// Test the format specifiers

// Restore this mask so diags and the shutdown message will print correctly!
ACE_LOG_MSG->priority_mask (ACE_LOG_MSG->priority_mask () | LM_DEBUG | LM_ERROR,
ACE_Log_Msg::PROCESS);

ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("**** running format specifiers test\n")));

if (status += test_format_specs ())
{
ACE_ERROR ((LM_ERROR, ACE_TEXT ("logging specifier tests failed!\n")));
status = 1;
}

ACE_END_TEST; // 如果前面屏蔽掉了 ACE_START_TEST,那么也要把这句屏蔽,否则编译出错。

getchar();

return status;
}


进一步研究后知道,Test_Output 是 \ACE-6.0.0\ACE_wrappers\tests\ 目录下的一个公用的DLL库,功能是设置其他程序的日志输出文件,不是标准输出,而 ACE_START_TEST 和 ACE_END_TEST 宏就是在 Test_Output 的代码里定义的,所以 ACE_DEBUG 没有打印信息到窗口。Log_Msg_Test 程序通过 Test_Output 设置了输出日志为 \ACE-6.0.0\ACE_wrappers\tests\log 目录下的 Log_Msg_Test.log
文件。这些都可以通过执行Log_Msg_Test 程序,断点调试 Test_Output 的代码得知。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: