View Full Version : defines
EscapeCharacter
03-24-2002, 02:28 AM
is there some way to implement something like the ifdef directive in java? like if i want to add #ifdef __DEBUG__ code... #endif?
java doesn't have a preprocessor... so you have two options:
a) run cpp on your code before you compile it (C preprocessor).. (hey, why not? oh, because it would confuse the heck out of everyone else)
b) create a final int DEBUG = 0 [or 1, obviously] in the class, and just do if (DEBUG) { etc.}
Dru Lee Parsec
03-24-2002, 03:17 PM
THere is a new Jarkarta project called log4j (Logging For Java) It's available for free at http://jakarta.apache.org/log4j/docs/index.html
log4j allows you to have a property file that defines different levels of debug messages for various packages, classes, or methods. WIthin your code you insert some debugging code that can either print out or not print out depending on the property file .
There are a couple of nice things abour this approach:
1. You can turn the debug messages on or off via the property file. This means you DO NOT have to recompile to turn your debug messages off.
2. You may have high level of debug messages for one class, and a lower level of messages for another class, and no messages for yet another. Essentially you can set the debug level of each package/class independently.
3. The class inheirent their debug level. So you you set the package com.coderforum.gui to low level of debugging then every class in that package is automatically set to "low". But if you then set com.codeforum.gui.OthelloFrame to "High" it overloads that one class while all other classes in that same package continue to have the "low" level of debugging.
It's a pretty nice system. We're going to start using it at work so I need to learn how to set it up. There are other projects at work that are already using it and they've told me that log4j is pretty easy to set up.
Hope it helps.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.