本文主要是介绍ACE log使用助记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基本使用:
ACE_DEBUG ( (LM_DEBUG, "no file found/n") );
ACE_DEBUG ( (LM_DEBUG, "piece%d", i) );
ACE_ERROR_RETURN ( (LM_ERROR, "get file %s faild/n", filename), -1 );
log的严重等级有如下的几种:
LM_TRACE Messages indicating function-calling sequence
LM_DEBUG Debugging information
LM_INFO Messages that contain information normally of use only when debugging a program
LM_NOTICE Conditions that are not error conditions but that may require special handling
LM_WARNING Warning messages
LM_ERROR Error messages
LM_CRITICAL Critical conditions, such as hard device errors
LM_ALERT A condition that should be corrected immediately, such as a corrupted database
LM_EMERGENCY A panic condition, normally broadcast to all usersLM_TRACE Messages indicating function-calling sequence
格式化输出的参数有如下几种:
Code Argument Type Displays
A ACE_timer_t 浮点数
a — 导致程序终止(Abort)
c char 单个字符
C char* 字符串(narrow characters)
i,d int 10进制整数
I — 缩进
e,E,f,F,g,G double 双精度浮点数
l — 行号
M — severity level的名称
m — 错误号(errorno)
N — 文件名
n — ACE_Log_Msg::open()指定的程序名
o int 八进制整数
P — 当前进程ID
p ACE_TCHAR* 字符串,后接错误号,同perror
Q ACE_UINT64 64位无符号十进制整数
r void (*)() 函数调用
R int 十进制整数
S int 数字对应的信号名称
s ACE_TCHAR* ACE_TCHAR类型的字符串
T — 当前时间(hour:minute:sec.usec)
D — 时戳(month/day/year/hour:minute:sec.usec)
t — 当前线程ID
u int 无符号十进制整数
w wchar_t Single wide character
W wchar_t* Wide-character string
x,X int 十六进制数
@ void* 指针(十六进制)
% N/A %
屏蔽方法:
例如不想让ACE_DEBUG和ACE_ERROR的调用输出,可以在包含Log_Msg.h前定义宏:
#define ACE_NLOGGING
再比如不想让LM_DEBUG级别的信息输出,可以在程序里添加:
ACE_Log_Msg::disable_debug_messages(LM_DEBUG);
ACE_Log_Msg::enable_debug_messages(LM_ERROR);
线程或进程配置:
ACE_LOG_MSG->msg_callback(logcallback);
ACE_LOG_MSG->priority_mask(0,ACE_Log_Msg::PROCESS);
定制自己的消息处理:
例如希望将调试信息输出处理一下再进行输出,可以这样:
class MyCallBack: ACE_Log_Msg_Callback{
public:
void log(ACE_Log_Record& record){
printf("%s/n",record.msg_data());//do what you want with the record
}
};
MyCallBack call;
ACE_LOG_MSG->msg_callback((ACE_Log_Msg_Callback*)&call);
ACE_LOG_MSG->clr_flags(ACE_LOG_MSG->STDERR);
ACE_LOG_MSG->set_flags(ACE_LOG_MSG->MSG_CALLBACK);
再比如希望输出到日志文件,可以这样:
std::ofstream log("test.log");
ACE_LOG_MSG->msg_ostream(&log);
ACE_LOG_MSG->set_flags(ACE_LOG_MSG->OSTREAM);
这篇关于ACE log使用助记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!