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