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);


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值