[Wind] Ace notes (1)-Log message management

Source: Internet
Author: User
ACE provides flexible and convenient log management and message output functions. The following describes some simple and direct functions.

Ace_debug common output messages
Ace_error provides some low-level messages about program errors.

The usage of the two macros is consistent.
Ace_debug (error level, "Format String", variable 1... Variable N)

Some Error-level systems are defined as follows:
Lm_shutdown = 01, system crash level
Lm_trace = 02, Trace Level
Lm_debug = 04, debug level
Lm_info = 010, general information level
Lm_notice = 020, Attention Level
Lm_warning = 040, warning level
Lm_startup = 0100, startup level
Lm_error = 0200, error level
Lm_critical = 0400, critical level
Lm_alert = 01000, recoverable Warning Level
Lm_emergency = 02000, Global Warning Level
Some format strings are used as follows:
Similar to the use of printf in C
% N-current program name of the table
% T-current thread Number of the table
% P-Table pointer
% S-string
 
Ace manages and controls the output through the Global Single Instance ace_log_msg. We can use this instance to redirect the output to the file or to the flag output.
The following table lists the levels of messages that can be output:

Ace_log_msg-> set_flags (ace_log_msg: stderr );
Set output to standard error output
Ace_log_msg-> clr_flags (ace_log_msg: stderr );
Disable output to flag error output
Ace_log_msg-> set_flags (ace_log_msg: ostream );
Ofstream mystream (filename, IOS: Out | IOs: trunc );
Ace_log_msg-> msg_ostream (& mystream );
Set output to file
U_long priority_mask = ace_log_msg-> priority_mask (ace_log_msg: process );
Ace_set_bits (priority_mask, lm_debug | lm_info );
Set to only record messages at the lm_debug or lm_info level
Ace_clr_bits (priority_mask, lm_debug | lm_info );
Clear setting conditions
Ace_log_msg also has a very interesting function, which can output blocks in the memory in hexadecimal mode. The simple usage is as follows:
Ace_log_msg-> log_hexdump (lm_debug,
(Char *) array,
Sizeof array );

The following is an example. The example is from the example program in the ace package.
# Include "ACE/OS _main.h"
# Include "ACE/streams. H"
# Include "ACE/log_msg.h"
Int
Ace_tmain (INT, ace_tchar * [])
{
// The message will be output to stderr.
Ace_debug (lm_debug,
"First message/N "));
Ace_log_msg-> clr_flags (ace_log_msg: stderr );
// The message will not be output because the flag is cleared.
Ace_debug (lm_debug,
"Second message/N "));
Ace_log_msg-> set_flags (ace_log_msg: ostream );
// The message will not be output because the stream entity has not been defined
Ace_debug (lm_debug,
"Third message/N "));
// Create a stream object pointing to the D:/output. Log File
Const char * filename = "D: // output. log ";
Ofstream mystream (filename, IOS: Out | IOs: trunc );
If (mystream. Bad ())
Return 1;
// Set output to stream
Ace_log_msg-> msg_ostream (& mystream );
// The message will be output to the file.
Ace_debug (lm_debug,
"Fourth message/N "));
Ace_log_msg-> set_flags (ace_log_msg: stderr );
// This message will be output to both the file and stderr.
Ace_debug (lm_debug,
"Th message/N "));
Return 0;
}
 
Well, there are more functions in the ace diary management function,
I will write in ACE skills and ACE application articles;
For example, you can use command line parameters to configure log parameter output and how to configure logs through configuration files.

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.