You can use the JDK's inbuilt logger
http://docs.oracle.com/javase/6/docs/api/java/util/logging/package-summary.html
It's very simple to use and configure, yet flexible (e.g. logging levels) when you want it to be. Also, you don't have to include any third party libraries.
This example shows two ways of using the log method
import java.util.logging.Level;
import java.util.logging.Logger;
..........
private static final Logger logger = Logger.getLogger(Test.class.getName());
private void setup(String val1) {
logger.info("Entering method with value [" + val1 + "]");
//Do something here
try {
//Do something here
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to prune the hedge", e);
}
}
The logging levels are arranged according to a hierarchy - enabling logging for a specific Level implies logging will be done for that level and "higher" levels. E.g. enabling Level.INFO will log all messages logged with INFO, WARNING and SEVERE messages.
If you wish to turn off logging at a specific level, you can configure this in a properties file. E.g. a configuration file with only console output and logging enabled for Level.WARNING and above will look like this
handlers = java.util.logging.ConsoleHandler
.level = WARNING
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
This file needs to be included with a system property when you run your program
java -Djava.util.logging.config.file -cp <your classpath> <your main class>