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


 

發佈了43 篇原創文章 · 獲贊 0 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章