ACE Server programming 5: ACE log output and tracking, ace Server
The server program often needs to display the error message, status, or trace the execution path of the program in the command line. The simplest method is to use printf.
ACE provides more powerful log facilities:
1. enable or disable macros during compilation;
2. enable or disable macros dynamically;
3. Log severity levels are supported;
4. Log redirection is supported;
5. multi-thread security and line-level configuration are supported;
To use the log-related functions of ACE, you must introduce the header file <ace/Log_Msg.h>.
ACE log output
ACE provides two macros to support log output: ACE_DEBUG and ACE_ERROR.
The internal implementation and behavior of these two macros are the same, just to distinguish the debugging information and error information in semantics.
Before introducing the <ace/Log_Msg.h> header file, add the following definitions to disable log output. ACE_DEBUG and ACE_ERROR are replaced with null statements:
#define ACE_NLOGGING 1
Examples of ACE_DEBUG and ACE_ERROR:
ACE_DEBUG((LM_STARTUP, ACE_TEXT("Startup.\n")));ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("hook2: %d\n"), *paramp));ACE_ERROR((LM_ERROR, ACE_TEXT("config file %s is not found.\n"), szConfigFile.c_str())
When using ACE_DEBUG and ACE_ERROR macros, you must use two pairs of brackets to enclose parameters.
The first parameter is the severity level. ACE can configure the log severity level to display or disable log output at this level:
LM_DEBUG, LM_ERROR, LM_INFO, LM_ALERT, LM_WARNING, etc. The level has no priority. The most common problems are LM_DEBUG and LM_ERROR.
The second parameter supports formatting strings. Common instruction sets:
% A: Floating Point Number
% S: String
% D: decimal number
% M: Severity Level
% N: File Name
% P: process ID
% T: thread ID
% D: Current Time
% I: Indent
ACE call tracking
ACE defines the ACE_TRACE macro used to trace the call of a function. Specifically, it generates an output at the place it defines and generates another output when it exits its scope.
The implementation of ACE_TRACE is expanded as an object on a stack, and logs are output in its constructor and destructor respectively.
void foo(){ ACE_TRACE(ACE_TEXT("foo\n")) int a = 0; int b = 0; int c = b;}
ACE_TRACE only receives a single string and does not support formatting. The output log severity level is LM_TRACE.
ACE_TRACE is disabled by default. Some online users often report that they cannot see the output of ACE_TRACE. Many answers are also incorrect. It is also impossible to define # define ACE_NTRACE 0 in the project.
You must define and recompile the ace library before referencing other header files in the ACE/config. h header file:
#define ACE_NTRACE 0
Record, for better yourself! Reprinted please indicate the source!