Macros for debugging and tracing C++ programs.
DEBUGLOG, TRACELOG: general macros for debugging. They require having
defined previously the macro DEBUG to an int value
(1-> no pauses after each log; 2-> pause after each log),
or to have it undefined if we do not require debugging.
These macros define two modalities of debugging/tracing:
- Debug: they are log traces that can be activated/deactivated only globally, for the entire code. They are recommended for logging the progress of important parts of the program. Once DEBUG is undefined, they do not generate any code. The DEBUG constant can be also used for including pieces of code in the program, e.g., checkings that we wish to get rid of after debugging (but that are useful during that phase for catching unexpected errors), alternative algorithms that are slower and not suitable for production but are good for detecting bugs, etc.
- Trace: they are traces with the scope of a method/function. They can be enabled/disabled for that method as described below. They are recommended for detecting difficult bugs in particular portions of code that, once fixed, should be left there for the case of tracing future uses of the code. If disabled, they do not generate code.
NOTE:
-Traces also require to define the DEBUG constant
-Include this file after defining (or undefining) the DEBUG const
and OUTSIDE any namespace.
- Copyright
- See LICENSE.txt and AUTHORS.txt file.
http://jafma.net
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
There are two cases:
- DEBUG is defined (before including this file). In that case, either DEBUG == 2 or not (typically, DEBUG == 1). In the former case a pause will be done by requesting an integer from console after each DEBUG(txt). In any case, defining DEBUG enables the use of the transient debugging macro, TRACE(txt). For transient, method-scope debugs, define at the beginning of the method a TRACE(txt) equal to TRACELOG(txt) and undefine it at the end of the method. Then use TRACE(txt) for the transient debug logs in the method. If you need finer traces (e.g., containing code), define your own macro in the routine and undefine it later, e.g., FINETRACE.
- DEBUG is not defined. In that case all these macros are defined to empty in order not to generate any code.
|
#define | DEBUGLOG(txt) |
|
#define | TRACELOG(txt) |
|
◆ DEBUGLOG
◆ TRACELOG