用 -m 限制日志大小怎么没有用呢?
我的程序-------------------------------------------------------------------------------------------------
#include"ace/OS.h"
#include "ace/Log_Msg.h"
#include "ace/Service_Config.h"
#include <ace/ACE.h>
#include <ace/Configuration.h>
#include <ace/OS_main.h>
#include <ace/OS_NS_netdb.h>
int ACE_TMAIN(int argc, ACE_TCHAR* argv[])
{
if (ACE_Service_Config::open (argc,
argv,
ACE_DEFAULT_LOGGER_KEY,
1,
0,
1) < 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("Service Config open")),
1);
for(int j = 0; j < 10000000; j++) {
for(int i = 0; i < 998; i++) {
ACE_DEBUG((LM_WARNING, "-"));
}
ACE_DEBUG((LM_WARNING, "\r\n"));
}
while(1) {
ACE_OS::sleep(1);
}
return 0;
}
----------------------------------------------------------------------------------------------------------
配置文件
dynamic Logger Service_Object * ACE:_make_ACE_Logging_Strategy()
"-m 1-i 1 -N 1 -s log.out -f STDERR|OSTREAM -p WARNING|~DEBUG"
我已经写了-m 1了,但是日志还是超过1K,不知道为什么? ACE -m 日志不是那么精确的,因为它是通过 -i 确定检查时间的,如果在那个时间内写了大量信息就有这个问题,如果你要精确的方法,建设使用回调来写日志 谢谢楼上的朋友。
“因为它是通过 -i 确定检查时间的”是一个重要的原因。
但是我现在觉得最上面的代码得不到想要的结果最主要的原因是ACE_Reactor::instance()->run_reactor_event_loop(); 与输出写在同一个线程中。
将输出放在另一个线程中就可以在很大程度上控制文件的大小了。我将
for(int j = 0; j < 10000000; j++) {
for(int i = 0; i < 998; i++) {
ACE_DEBUG((LM_WARNING, "-"));
}
ACE_DEBUG((LM_WARNING, "\r\n"));
for(int j = 0; j < 10; j++) {
for(int i = 0; i < 998; i++) {
ACE_DEBUG((LM_WARNING, "-"));
}
ACE_DEBUG((LM_WARNING, "j = %d\r\n", j));
最后得到的结果为
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------j = 7
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------j = 8
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------j = 9
文件大小大约为3k
页:
[1]