ACE Server programming 5: ACE log output and tracking, ace Server

Source: Internet
Author: User

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!

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.