This is an old revision of the document!
private static Logger logger = Logger.getLogger(MyClass.class); ... logger.info("BUTTON step backward"); ... if (logger.isTraceEnabled()) logger.trace("lo: " + lo + " hi: " + hi + " min: " + min + " max: " + max + " rel: " + rel); ... if ((new File("log4j.properties")).canRead()) PropertyConfigurator.configure("log4j.properties");
… because it is easier than
// System.out.println(...) all over the code
Since JDK 1.4 there is a logging framework inside the Java core packages.
AFAIK log4j provides more features and is at least as stable, so I keep using log4j.
Read more opinions http://www.google.at/search?q=log4j+java.util.logging
Commons Logging seems to be a compatibility layer so that a library can work with different logging implementations.
Whatever you do, don't break your program:
If the program reads a
log4.properties file from the file system,
the file will likely get lost and users will be confronted with a
and might not be able to run the program.
Here is a solution that works well for me:
log4j.propertiesfile is located in the root directory of the classpath
log4j.propertiesfile is located in the working directory
log4j.propertiesexists in the working directory
log4j.propertiesfrom the working directory AND