Simple C/C ++ logs

Source: Internet
Author: User

C/C ++ does not have a standard logstore, which is directly replaced by printf. However, it does not support hierarchical control of output information. It seems too important to use log4cpp. Here I will give a few simple log functions that I often use.

[Cpp]
# Include <stdio. h>
# If defined (DEBUG)
# Define debug (...) {fprintf (stderr, _ VA_ARGS _); fflush (stderr );}
# Else
# Define debug (...)
# Endif
 
# If defined (DEBUG) | defined (INFO)
# Define info (...) {fprintf (stderr, _ VA_ARGS _); fflush (stderr );}
# Else
# Define info (...)
# Endif
 
# If defined (DEBUG) | defined (INFO) | defined (ERROR)
# Define error (...) {fprintf (stderr, _ VA_ARGS _); fflush (stderr );}
# Else
# Define error (...)
# Endif
 
 
Main ()
{
Debug ("1% d \ n", 23 );
Info ("2% d \ n", 23 );
Error ("3% d \ n", 23 );
}
Define DEBUG, INFO, or ERROR in makefile or project to specify different output levels. If this parameter is not defined, no output is required.


From the column of ani_di
 

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.