Turning Off Compilation of DebugLogging Code

Top  Previous  Next

A main design guideline for the JrDebugLogger code was that it be easy to tell your compiler to compile code that removed all debug log related code from the compiled application, so as to ensure no performance costs for code generated without debugging functions.

 

The options described here are configured through the jrdebug_switch.h file, or can be overridden by passing -D define statements in your project or makefile.

 


There are actually two ways to turn off debug output from your code:

You can completely turn off the compilation of the debug code - the actual debug logging code is not compiled-in, and should have absolutely no impact on your code at all.
You can leave the code compiled in, but disable it at startup (and re-enable it when you want).

 

The second option can be very useful if you want to allow your program to be run with debugging enabled, and JrDebugLogger even includes a simple commandline parsing helper function to automatically look for the -dbf commandline option and enable debug logging to file if it is found.

 

Even when debug logging code is compiled-in but disabled, JrDebugLogger was designed to have absolutely minimal impact on runtime performance.  None of debug output function calls are evaluated when logging is disabled - all calls amount to just a simple compare and jump statement.

 

You can control the conditional compilation of debugging functions by defining a symbol described in the file jrdebug_switch.h. Just uncomment lines to build code that has all debugging functions removed or disabled.

In fact, the jrdebug_switch.h file serves no other purpose than to let you specify these compilation flags:

 

// Usually you want to automatically enable logging when you build

//  in Debug mode, and not compile-in logging when you build in release mode

//  (signified when symbol NDEBUG is defined); this also checks for the symbols

//  DEBUG and __DEBUG__ to indicate a debug compilation switch.

#define JrDebugDIRECTIVE_ObeyNDEBUG

 

// If you want to always disable all debugging and eliminate all runtime

//  overhead, unless overriding with -D define, just uncomment this line to

//  prevent debugging code from being compiled in:

// #define JrDebugDIRECTIVE_DontCompileDebugging

 

// If you want to compile in the ability to turn on debugging at runtime, but

//  turn off debugging at startup, you can define the following symbol (note

//  it has no effect if debugging is compiled out):

// #define JrDebugDIRECTIVE_StartupDisabled

 

// If this symbol is not set then a minimal extra function will be compiled-in

//  even when debugging is set to not compile-in, which will warn any

//  user if they try to invoke a debug commandline flag.

#define JrDebugDIRECTIVE_CompiledOutCommandlineParseOff

 

 


See also: The advanced discussion of compiling-in options for instructions on working with the jrdebug_switch.h file and compiler flag overrides.